01_正则表达式_03_替换

【替换】

public String replaceAll( String regex,String replacement );

使用给定的 replacement 替换此字符串所有匹配给定的正则表达式的 子字符串 。

str.replaceAll(regex,repl)方法等同于 Pattern.compile(regex).matcher(str).replaceAll(repl);

regex:用来匹配此字符串的正则表达式

replacement:用来替换每个匹配项的字符串

返回值为替换后的字符串

 

【1.将字符串中的 长度超过5的子数字字符串 替换为 #】

 

【2.将字符串中的叠词 替换成&】 

 

【3.将字符串中的叠词替换成单字符 如 :qweeeeerwww -----> qwerw】

 

 

posted @ 2016-08-26 18:52  HigginCui  阅读(274)  评论(0编辑  收藏  举报