Catalogue search: type a pattern and flags, every match is framed and every group coloured. A pattern that hangs is stopped, the page keeps running. An…
Why it matters
Regexes live in form validation, search, log reading, find-and-replace. They are feared for being abstract, but once the matches light up, the pattern makes sense. Plus three traps that often become bugs: lastIndex with the g flag, an unescaped dot, and a pattern that hangs.
The key idea
A regex matches the shape of text; the g flag and capture groups confuse the most
Try it in this playground
Use the ready pattern Email, then Hashtag Watch the match frames on the board. Hashtag has a group: the word after # gets its own colour.
Turn the g flag off Only the first match is framed. Turn it back on and they all return: the first match against every match.
Write a pattern with a capture group of your own Wrap part of the pattern in brackets. Every group gets its own colour on the board and shows in the match list.
Edit the test text yourself Type your own text: the match frames change as you type.