Pattern: Regular expression

“Regular expression” is one of the patterns that you can select on the Match panel. With this pattern you can insert actual regular expression code into your regular expression.

One handy aspect of the “regular expression” pattern is that it accepts a regular expression in any of the regular expression flavors that RegexMagic supports. This flavor can be a different one than the regex flavor used by the application you have selected on the Regex panel. RegexMagic automatically converts the regular expression from the flavor you specified in the pattern to the flavor selected on the Regex panel.

In this example, we’ll use this ability to take a regular expression that you might have found in old source code that was created for a legacy regular expression flavor and convert it to a modern flavor. You can find this example as “Pattern: regular expression” in the RegexMagic library.

  1. Click the New Formula button on the top toolbar to clear out all settings on the Samples, Match, and Action panels.
  2. Set both “begin regex match at” and “end regex match at” to “anywhere”. This makes sure RegexMagic does not add any anchors to our regular expression.
  3. Click the Add First Field button to add field 1.
  4. In the “pattern to match field” drop-down list, select “regular expression”.



  5. In the “regular expression flavor” drop-down list, select GNU BRE.
  6. Tick the “case insensitive” checkbox.
  7. Paste in this regular expression:
    \(\(I\|you\|we\|they\)\s\+love\|s\?he\s\+loves\)\s*reg\(ular expressions\?\|ex\(p\|es\)\?\)
  8. On the Regex panel, select “C# (.NET 2.0–7.0)” as your application, turn off free-spacing, and turn off mode modifiers. Click the Generate button, and RegexMagic converts the regex from the GNU BRE flavor to the JGsoft flavor:
    ((I|you|we|they)[\t\n\v\f\r ]+love|s?he[\t\n\v\f\r ]+loves)[\t\n\v\f\r ]*reg(ular expressions?|ex(p|es)?)

    Required options: Case insensitive; Exact spacing.
    Unused options: Dot doesn’t match line breaks; ^$ don’t match at line breaks; Numbered capture.

Reference