1 class Test 2 { 3 public static void main(String[] args) 4 { 5 String str = "xia..as....yuan.com"; 6 7 //判断 8 boolean b1 = str.endsWith(".com"); 9 boolean b2 = str.startsWith("xia"); 10 System.out.println(b1); 11 System.out.println(b2); 12 13 //切割 14 String regex = "\.+"; 15 String[] arr = str.split(regex); 16 for(String s:arr) 17 { 18 System.out.println(s); 19 } 20 21 //替换 22 String regex1 = "\.+"; 23 String s1 = str.replaceAll(regex1,"*"); 24 System.out.println(s1); 25 26 //多个标符变一个 27 String regex2 = "(.)\1+"; 28 String s2 = str.replaceAll(regex2,"$1"); 29 System.out.println(s2); 30 } 31 }
//对于匹配:可以查看API,找到匹配器Pattern以及match即可