Replacement Methods of Matcher Class

In this lesson, you will learn how to perform the String replacement methods of the Matcher class and capture groups in the regular expressions.

We'll cover the following

The Matcher class

The Matcher class also defines methods for replacing matched strings with a new replacement string.

Replacement methods

To replacing text in an input string, we use replacement methods.

Matcher appendReplacement(StringBuffer sb, String replacement) - Implements a non-terminal append-and-replace step.

Below is a code example demonstrating the use of the appendReplacement() method:

Get hands-on with 1200+ tech skills courses.