Regular expressions are powerful and easy to get subtly wrong. These seven mistakes cause most of the production bugs I have seen.

1. Catastrophic backtracking

Nested quantifiers like (a+)+$ can take exponential time on a non-matching input and freeze your server. Avoid nested repeats, or use atomic groups or possessive quantifiers where supported.

2. Greedy matching

<.*> on <b>bold</b> matches the whole string. Use the lazy form <.*?> or a negated class <[^>]*>.

3. Forgetting to escape the dot

example.com also matches exampleXcom. Escape it: example\.com.

4. Anchors without the multiline flag

^ and $ match only the start and end of the whole string unless you pass m. For line-by-line matching, use /^foo$/m.

5. The global flag and lastIndex

In JavaScript, a regex with g keeps lastIndex between .test() calls, so the same input can return true then false. Create a fresh regex or reset lastIndex = 0.

6. Validating emails with a giant pattern

A perfect email regex does not exist. Check for one @ and a dot in the domain, then confirm by sending a message.

7. Assuming ASCII

\w does not match accented letters. Use the u flag with Unicode property escapes: /\p{L}+/u.

Try it: Regex Tester
Related: Regex Explainer and Regex Cheatsheet. All 590+ tools at webdevtoolbox.com run client-side.