Codrix — Regular Expression Syntax Basics | codrix.org
An ordered procedure: write the literal text, escape special characters, add a character class, add repetition, anchor the pattern, then test against matching and non-matching lines.
Step 1: write the literal text. Type the exact substring you want to find and run the pattern. Failure mode at this step: the pattern matches nothing because the text contains a character you did not type, such as a trailing space or a different case.
Step 2: escape special characters. Any character with a meaning in the dialect must be preceded by a backslash to be matched literally. Failure mode: the pattern silently matches something else, because an unescaped metacharacter was read as an instruction rather than a literal.
Step 3: add a character class for the parts that vary. Replace the varying characters with a bracketed set that lists them. Failure mode: the class is too wide and matches characters you did not intend, or too narrow and misses valid variants.
On narrow screens, swipe or scroll the plate sideways.
Step 4: add repetition. Use star, plus or question mark on the element that repeats, wrapping it in parentheses when the repeated unit is longer than one character. Failure mode: the operator binds to the last character only, so the pattern matches a suffix instead of the whole run.
Step 5: anchor the pattern. Place the caret or the dollar sign to constrain where the match may start or end. Failure mode: the pattern matches the substring anywhere in the line, including inside a longer word.
Step 6: test against matching and non-matching lines. Keep both sets in the test file and run the pattern after every change. Failure mode: the pattern matches everything or nothing, which means the specification is incomplete rather than the engine being wrong.
Further reading