Java replaceAll() 方法
replaceAll() 方法使用给定的参数 replacement 替换字符串所有匹配给定的正则表达式的子字符串。
语法
public String replaceAll(String regex, String replacement)
参数
regex -- 匹配此字符串的正则表达式
newChar -- 用来替换每个匹配项的字符串
返回值
成功则返回替换的字符串,失败则返回原始字符串
实例
public class Test { public static void main(String args[]) { String Str = new String("www.google.com"); System.out.print("return :" ); System.out.println(Str.replaceAll("(.*)google(.*)", "facesoho" )); System.out.print("return :" ); System.out.println(Str.replaceAll("(.*)taobao(.*)", "facesoho" )); } }
以上程序执行结果为:
return :facesoho return :www.google.com
尊贵的董事大人
英文标题不为空时 视为本栏投稿
需要关键字 描述 英文标题