Pattern: List of literal text

“List of literal text” is one of the patterns that you can select on the Match panel. Use this pattern to make a field match a piece of text from a list that you provide. If you repeat the field, a different item from the list may be matched with each repetition.

This example shows how you can use the “list of literal text” pattern to easily match one of several words. You can find this example as “Pattern: list of 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:
    Mary, Sue, and Betty had a little lamb.
  3. On the Match panel, set “begin regex match at” to “start of word”, and set “end regex match at” to “end of word”.
  4. Click the Add First Field button to add field 1.
  5. In the “pattern to match field” drop-down list, select “list of literal text”.



  6. Enter these three words, one per line:
    Mary
    Sue
    Betty
  7. Set the “field validation mode” to “average”.
  8. 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:
    \b(?:Betty|Mary|Sue)\b

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

  9. The Samples panel now shows that this regular expression correctly matches the three names in three separate regex matches:
    Mary, Sue, and Betty had a little lamb.

Related Examples

Reference