Every week I lose 20 minutes to the same dumb regex bug. Not a clever one — a dumb one. The pattern looks right, the test string looks right, and the match count says 0.
Regex has a tiny set of failure modes and they repeat forever. Here are the five I actually hit, with the fix for each. Paste them into any tester as you read — seeing the match change is the whole lesson.
1. Greedy .* eats your whole string
You want the quoted words out of this:
say "hi" then "bye"
Enter fullscreen mode
Exit fullscreen mode
Pattern ".*" matches "hi" then "bye" — one giant match, because .* is greedy and grabs as much as it can.
Fix: make it lazy with ? :
".*?"
Enter fullscreen mode
Exit fullscreen mode
Now you get "hi" and "bye" separately. If you want the inside without quotes, capture it: "([^"]*)" — group 1 holds the words.
2.…