Menu

Test Your Regex in the Browser: 5 Real Bugs + a Free Online Tester
📰

Test Your Regex in the Browser: 5 Real Bugs + a Free Online Tester

DEV Community: javascript·Sujal Khatri·4 days ago
#s8UR6u7e
#devtojavascript#devto#dev#regex#article
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.