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

The appendReplacement(StringBuffer sb, String replacement) method

This method is intended to be used in a loop together with the appendTail and find methods. Once we get a match using the find() method, we can call the appendReplacement() method to operate on each match and replace the matched text. Finally, it appends the replaced text to StringBuffer. It reads characters from the input sequence, starting at the append position, and appends them to the given string buffer. It stops after reading the last character preceding the previous match, that is, the character at index start() - 1.

The replacement string may contain references to subsequences captured during the previous match. All the rules of replacement reference we String.replaceAll ...

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