zoukankan      html  css  js  c++  java
  • Java 正则表达式 regex 提取字符

    直接上代码:

     1 @Test
     2 
     3     public void contextLoads() {
     4 
     5         /*String str="this is (Tom) and "Eric", this is "Bruce lee", he is a chinese, name is "李小龙"。";
     6 
     7         Pattern p= Pattern.compile(""(.*?)"");
     8 
     9         Matcher m=p.matcher(str);
    10 
    11         while(m.find()){
    12 
    13             System.out.println(m.group());
    14 
    15         }*/
    16 
    17  
    18 
    19  
    20 
    21         /*String str="this is [Tom] and , he is a [chinese], name [is]。";
    22 
    23         Matcher mat = Pattern.compile("(?<=\[)(\S+)(?=\])").matcher(str);
    24 
    25         while(mat.find()){
    26 
    27             System.out.println(mat.group());
    28 
    29         }*/
    30 
    31  
    32 
    33  
    34 
    35         String filetext = "//[张小名] 25分//[李小花] 43分//[王力] 100分";
    36 
    37         Pattern p = Pattern.compile("\[(.*?)\]");//正则表达式,取=和|之间的字符串,不包括=和|
    38 
    39         Matcher m = p.matcher(filetext);
    40 
    41         while(m.find()) {
    42 
    43             System.out.println(m.group(0));//m.group(1)不包括这两个字符
    44 
    45         }
    46 
    47     }
  • 相关阅读:
    APP测试-流量测试
    APP测试-流畅度测试
    APP测试-耗电分析
    工具安装-Homebrew
    工具安装-go for Mac
    APP测试-耗电量测试
    APP测试-CPU测试
    APP测试-内存测试
    APP测试-monkey
    APP测试-adb命令
  • 原文地址:https://www.cnblogs.com/smartisn/p/12276032.html
Copyright © 2011-2022 走看看