Tool to perform MULTIPLE regex replacements on text

It's often been the case that I've wanted to a) perform a series of regex replacements on some text in a specific order, and b) save this replacement to use for later. However, despite the purported usefulness of such a tool, I have not found a program, convenient shell script, or online utility which allows a user to do this.

I will list a number of programs and utilities that I have tried:

  1. Sublime Text: this works well, but only one regex replacement can be made at a time, which is rudimentary for my purposes.

  2. Regex101: This is an extremely invaluable tool for regex replacements, but it also doesn't support multiple substitutions.

  3. Perl: This is probably the best way to perform a series of replacements and save it as well for later. However, it is incredibly cumbersome to use, doesn't show a preview of the replacements that are being made, and has some really ugly syntax.

Is there a better way to do what I'm trying to do from the command line, from a program, or from an online website?


Solution 1:

You can do this in BBEdit using something called a "Text Factory".

A text factory (File => New => Text Factory) allows you to string together as many transformations (including Replace All, but there are many others) as you like.

Once you've set it up, you can apply it as a Text Filter to the active document (or selection range), or to a specific file, or folder, or multiple files/folders.

Solution 2:

BBEdit, LibreOffice, and similar tools allow regular expressions in their search/replace dialogues

Typically, there is a check box to allow regex or plain text. Then you can replace one at a time or click "replace all."