O'Reilly logo

Java 9 Regular Expressions by Anubhava Srivastava

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required