Method - String replaceAll(String regex, String replacement)

This method replaces each substring of the subject string that matches the given regular expression with the replacement String. As the name implies, replaceAll replaces all the matching occurrences of the input String. Note that we can also supply a simple String containing no regex meta character in the first argument.

Calling this method is equivalent to a call to the following:

Pattern.compile(regex).matcher(input).replaceAll(replacement); 
Note: We will cover Pattern and Matcher APIs in Chapter 5, Introduction to Java Regular Expression APIs - Pattern and Matcher Classes.

The replacement string allows the use of references to substrings, represented by the captured groups ...

Get Java 9 Regular Expressions now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.