This example demonstrates how you can prepare a search-and-replace action with RegexMagic to insert text before the regex match. In a regular expression, metacharacters need to be escaped. This example prepares a search-and-replace that does this. You could use this to insert a user-provided search term into a regular expression, for example. You can find this example as “Action: insert before and after match” in the RegexMagic library.
For this example, we’ll continue with the regular expression created in the example about the “regex metacharacter” pattern. That regular expression matches the metacharacters we want to escape. All we need to do is to use the settings on the Action panel to insert the escape character.

\\\g<0>
You could add the same action to the example about the “replacement metacharacter” pattern in order to escape metacharacters in replacement texts. Depending on your application’s replacement text syntax, the escape character to insert may need to be a dollar sign rather than a backslash.