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 }
Pattern
时间: 2024-10-26 11:47:15