Java String Replaceall
# Java replaceAll() Method
[Java String Class](https://example.com/java/java-string.html)
* * *
The replaceAll() method replaces all substrings of this string that match the given regular expression with the given replacement.
### Syntax
public String replaceAll(String regex, String replacement)
### Parameters
* **regex** -- The regular expression to which this string is to be matched.
* **replacement** -- The string to be substituted for each match.
### Return Value
Returns the replaced string on success, or the original string on failure.
### Example
## Example
public class Test {
public static void main(String args[]){
String Str =new String("www.google.com");
System.out.print("matching successful return value :");
System.out.println(Str.replaceAll("(.*)google(.*)", "tutorial"));
System.out.print("matching failed return value :");
System.out.println(Str.replaceAll("(.*)taobao(.*)", "tutorial"));
}
}
The execution result of the above program is:
Match success return value :tutorial Match failure return value :www.google.com
* * *
[Java String Class](https://example.com/java/java-string.html)
AI is thinking...
[](http://www.runo
YouTip