Back
Close

C# Professional - Processing Text

talent-agile
102.7K views
Previous: Regular Expressions - Groups & Capture

Regular Expressions - Replacing Text

As we saw before, regular expressions can specify groups in the pattern to capture data from the text.

But these groups can also be used for replacing data in a given text.

Note: Be careful when doing replacement, as the whole match will be replaced. Make sure you capture text that should be kept in the replacement if it is part of the pattern

Backreferences can be used for replacement using the $N syntax, where N is the number of the captured group that you want to use for replacement.

If you want to use named capture groups, you need to use the following syntax ${groupname}.

Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io