Java replaceAll () method
replaceAll () method uses the given parameters replacement of all the replacement string matches the given regular expression substring.
grammar
public String replaceAll(String regex, String replacement)
parameter
regex - matches the regular expression string.
newChar - the string used to replace each match.
return value
The success of the replacement string is returned, then failed to return the original string.
Examples
public class Test { public static void main(String args[]) { String Str = new String("www.google.com"); System.out.print("匹配成功返回值 :" ); System.out.println(Str.replaceAll("(.*)google(.*)", "w3big" )); System.out.print("匹配失败返回值 :" ); System.out.println(Str.replaceAll("(.*)taobao(.*)", "w3big" )); } }
The above program execution results:
匹配成功返回值 :w3big 匹配失败返回值 :www.google.com