比如对于字符串"abc,xyz,abc,kkk,qwerty',想要替换 abc 之后的逗号,而不替换 xyz 之后的,最终变成'abcxyz,abckkk,qwerty' 目前的办法是用 pattern matcher 找到符合的字符串在一个个替换
Pattern p = Pattern.compile("abc,"); Matcher m = p.matcher(input); while(m.find()){ input = input.replace(m.group(), m.group().replaceAll(",", "")); } 但是正则不是有断言之类的吗,能不能直接用 String 类的 replace 达到这样的效果?
