正则表达式经典实例

 1 public static String regular(String possess, String fill){
 2         //正则表达式
 3         String csrf_token = null;
 4         BufferedReader in;
 5         Pattern pattern = Pattern.compile(possess);
 6         in = new BufferedReader(new StringReader(fill));
 7         String s;
 8         try {
 9             while ((s = in.readLine()) != null){
10                 Matcher matcher = pattern.matcher(s);
11                 if (matcher.find())
12                 {
13                     csrf_token=matcher.group(1);
14                 }
15             }
16         } catch (IOException e) {
17             e.printStackTrace();
18         }
19         try {
20             in.close();
21         } catch (IOException e) {
22             e.printStackTrace();
23         }
24         return csrf_token;
25     }

 

1  //获取csrf_token值(使用正则)
2         csrf_token = LunTan.regular("name=\"csrf_token\" value=\"(.+?)\"/>", response);
3         System.out.println("csrf_token:" + csrf_token);
4         System.out.println("----------------------------------------");

 

转载于:https://www.cnblogs.com/sunny-sl/p/6735372.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值