Pattern: Literal text

“Literal text” is one of the patterns that you can select on the Match panel. Use this pattern to make a field match a specific piece of text exactly as you type it in.

This example shows how you can use the “literal text” pattern to make your regular expression match some text literally. You can find this example as “Pattern: literal text” 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. On the Samples panel, paste in one new sample:
    RegexMagic is a *great* tool for creating regexes!
  3. On the Match panel, set both “begin regex match at” and “end regex match at” to “anywhere”.
  4. Click the Add First Field button to add field 1.
  5. In the “pattern to match field” drop-down list, select “literal text”.

  6. Enter this text:
  7. On the Regex panel, select “C# (.NET 2.0–4.8 & .NET Core 1.0–3.0)” as your application, turn off free-spacing, and turn off mode modifiers. Click the Generate button, and you’ll get this regular expression which is the literal text we provided with all metacharacters escaped:

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

  8. The Samples panel now shows that this regular expression correctly matches the literal text we typed in:
    RegexMagic is a *great* tool for creating regexes!

Related Examples