import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ReplaceString {
public static void main(String[] args) {
StringBuilder text = new StringBuilder("It's SO very RUDE to shout !");
Matcher m = Pattern.compile("\\b[\\p{Lu}\\p{Lt}]+\\b").matcher(text);
while (m.find()) {
text.replace(m.start(), m.end(), m.group().toLowerCase());
System.out.println(">>>>>> "+m.group(0));
}
//注意这二者(find,matches)之间的区别,jdk源码中很清楚
if(m.matches()){
System.out.println(">>>>>> "+m.group(0));
}
System.out.println(text);
}
}
精通正则表达式383页例子展开
最新推荐文章于 2024-10-30 18:07:32 发布