The five mistakes everyone makes once
1. Using * when you meant +. The validator accepts empty input. Fix: use + when content is required.
2. Greedy .* for between-marker extraction. Eats past your intended endpoint. Fix: lazy .*? or negated class [^X]*.
3. \d+ at end of pattern with no anchor. Matches partial numbers. Fix: anchor with \b or $.
4. ? applied to the wrong thing. foo?bar makes the SECOND o optional, not 'foo'. To make 'foo' optional, group it: (foo)?bar.
5. {3,} with whitespace. {3, } with a space is interpreted as literal text in some flavors. Always tight: {3,}.
Debugging quantifier issues
When a pattern "works on test data but fails in production," the cause is almost always one of:
- Unanchored quantifier matching less than you expected.
- Greedy quantifier eating past the intended boundary.
*happily matching empty input that test data didn't include.
Add temporary anchors and test against the most adversarial input you can think of (empty string, very long string, only one character, all delimiters and no content).