C# Professional - Processing Text

talent-agile
104.1K views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content
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}.

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content