How to Create Capturing Groups and Replacement Text

In a regular expression, a capturing group isolates a part of the text matched by the regular expression. That allows you to grab part of the regular expression match, or to reuse that part in the replacement text when doing a search-and-replace. In RegexMagic, you can use the Action panel to create capturing groups that you’ll use for your own purposes. The example on capturing groups shows you how.

Capturing groups can also be used in search-and-replace actions. By using backreferences to capturing groups in the replacement text, you can reinsert parts of the regex match into the replacement. In RegexMagic, you can work that way with capturing groups, or you can just tell RegexMagic which fields you want to replace, and let RegexMagic figure out which capturing groups and backreferences to use. The replace fields example shows that.

To generate the replacement text, simply generate the regular expression. The replacement text is automatically generated with it.

When the replacement text is generated, you can see the results of the search-and-replace on the Samples panel if you select “samples and replacements” in the “show samples and/or replacements” drop-down list.