zoukankan      html  css  js  c++  java
  • 正则表达式经典实例

     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("----------------------------------------");
  • 相关阅读:
    表单
    框架
    表格
    列表
    标签
    封装类(包装类)
    常见类 --Object
    日志
    异常
    选择结构
  • 原文地址:https://www.cnblogs.com/sunny-sl/p/6735372.html
Copyright © 2011-2022 走看看