手机号的模糊处理:
phone.replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2")
替换包括\r\n\t为“”处理:
test.replaceAll("\r|\t|\n", "");
替换所有包括aoeiuAOEIU之一 剔除vowel内容:
str.replaceAll("[aoeiuAOEIU]", "");
判断字符串是否存在:
1 String reg = ".*/login.*|.*/manual.*";2 Pattern pattern = Pattern.compile(reg);3 String test = "/rest/loginMy";4 System.out.println(pattern.matcher(test).matches()); ---true
获取重复的字符串:
String abc = "DDF,ABC,BDF"; String arr = ".*(ABC|BBE|CCG).*"; String result = abc.replaceAll(arr, "$1"); // 另一种 Pattern regexp = Pattern.compile(arr); Matcher match = regexp.matcher(abc); match.matches(); String result = match.group(1);