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.
- Click the New Formula button on the top toolbar to clear out all settings on the Samples, Match, and Action panels.
- On the Samples panel, paste in one new sample:
Mary, Sue, and Betty had a little lamb.
- On the Match panel, set “begin regex match at” to “start of word”, and set “end regex match at” to “end of word”.
- Click the button to add field .
- In the “pattern to match field” drop-down list, select “list of literal text”.
- Enter these three words, one per line:
Mary
Sue
Betty
- Set the “field validation mode” to “average”.
- On the Regex panel, select “C# (.NET 2.0–8.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.
- 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