Java 正则表达式 匹配括号中的数字

第一种:
     String line = "+!!!0(100000000073);+!!!0(100000000071);";
     String pattern = "(?<=\\()\\d+(?=\\))";
     pattern = "(\\d{16})";
     Pattern r = Pattern.compile(pattern);
 
     Matcher m = r.matcher(line);
     while(m.find( )) {
        System.out.println("Found value: " + m.group(0) );
     }

Found value: 1000000000314473

Found value: 1000000000314771

第二种:

              String line = "1000000000314473);+@0(1000000000314771";
     String[] s = line.split("\\);\\+@0\\(");
     System.out.println(s[0]);

     System.out.println(s[1]);

第三种:

         String s1 = "折扣经济舱";
String s2 = ".*经济舱.*";
System.out.println(s1.matches(s2));//true

System.out.println(s2.matches(s1));//false

第四个:

                String s1 = "折扣经济舱";
String s2 = "经济舱";

Pattern p = Pattern.compile(s2);
   Matcher m = p.matcher(s1);
   if (m.find()) {
      System.out.println(1);
   }

   System.out.println(2);

输出结果是:1

2

猜你喜欢

转载自blog.csdn.net/chuan_zhang_ak/article/details/79494466