

In Japanese, digits can either be represented with the native Kanji characters (imported from Chinese), or with roman numerals. Several years after writing this trick, this very question came up on the RegexBuddy forum. (direct link) Example with Ten Replacements: Translating Japanese Digits In free-spacing mode, the regex looks like this: If it matches blue, we lookahead for bleu, which we know we'll find at the pool in the bottom, and capture it. We then use a pattern that matches blue or red.

Keeping our example, we just paste bleu rouge. In this version, at the bottom of the file, we temporarily paste a "pool" with the possible replacement texts. (direct link) Conditional Replacement using a Replacement Pool

I'll show you two similar idea (using a replacement pool or a dictionary) and some variations. You'll also need an editor with strong regex capabilities, such as EditPad Pro or Notepad++. Note that this technique will only work in flavors that allow you to set a capture within a lookahead. The purpose of this page is to show you a trick I came up with that allows you to do just that. You can insert new text, you can insert text matched by capture groups, but there is no syntax for conditional insertion, e.g, inserting bleu if you matched blue-at least not in any of the tools I know. In a text editor, however, it's a different story. From this light, regex replacements are really flexible.

In fact, if you wanted you could compute replacements by talking to a NASA server and requesting a piece of data from a machine on the moon. (Depending on context, such functions may be called lambdas, delegates or callbacks.) Using regex, this is no problem is most programming languages, where you can call a function to compute replacements.
