@Test    
  public void testtest() {
       String test = "hahahhehe sendCode\":\"12367890123rsdfsdfsdfdsahahhehe sendCode\":\"12367890123rsdfsdfsdfds";
       test = PropsUtil.regMatch(test, "sendCode\":\"([\\d]{8})([\\d]{3})");      

   }

    public static String regMatch(String withinText, String regString) {
        String code = null;
        Pattern pattern = Pattern.compile(regString);
        Matcher matcher = pattern.matcher(withinText);
        if (matcher.find()) {
            matcher.reset();
            while (matcher.find()) {
                code = matcher.group(1);
                System.err.println("aaaa" + code);
                code = matcher.group(0);
                System.err.println("bbbb" + code);
                code = matcher.group(2);
                System.err.println("ccc" + code);
            }
        }
        return code;
    }
}

运行结果

aaaa12367890
bbbbsendCode":"12367890123
bbbb123
aaaa12367890
bbbbsendCode":"12367890123
bbbb123

匹配后group(0)表示整个匹配的串

group(1)表示正则中第一个()中表示的正则匹配值

group(2)表示正则中第二个()中表示的正则匹配值

以此类推


 

相关文章:

  • 2022-12-23
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2021-06-04
  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2022-02-17
相关资源
相似解决方案