1 package 正则;
 2 
 3 import java.util.regex.Matcher;
 4 import java.util.regex.Pattern;
 5 
 6 public class Test_regex {
 7     public static void main(String[] args) {
 8         String str="a1b22c333d4444e_55_555f666666g7777777";
 9         String regex="\\w*";
10         Pattern pattern=Pattern.compile(regex);
11         Matcher matcher=pattern.matcher(str);
12         System.out.println(matcher.matches());//true
13     }
14 }
Matcher

 

 1 package 正则;
 2 
 3 import java.util.regex.Pattern;
 4 
 5 public class Test_regex {
 6     public static void main(String[] args) {
 7         String str="a1b22c333d4444e55555f666666g7777777";
 8         String regex="\\d+";
 9         Pattern pattern=Pattern.compile(regex);
10         for(String s:pattern.split(str))
11             System.out.print(s+" ");//a b c d e f g 
12     }
13 }

相关文章:

  • 2022-12-23
  • 2021-04-27
  • 2022-12-23
  • 2021-12-05
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-05
  • 2021-12-14
  • 2021-08-05
  • 2021-10-26
  • 2021-06-29
相关资源
相似解决方案