Write a regular expression — matches highlight in real time, and every token in the pattern is explained below. Plus a library of ready-made expressions for email, phones, dates, IPs and other common cases.
Regular expressions — a mini-language for pattern search and replace. JavaScript uses its own dialect (PCRE-inspired). Key parts: anchors (^ $ \b), classes (\d \w \s . [ ]), quantifiers (* + ? {n,m}), groups (( ) (?: )), alternation (|).
Flags
gimsuy
g · global · i · ignore case · m · multiline
g — find all matches, not just the first. i — case-insensitive. m — ^ and $ work per line. s — dot matches \n. u — Unicode. y — sticky (only from lastIndex). Flags combine: /.../gim.
Greedy vs lazy
Backtracking
.* — greedy · .*? — lazy
Quantifiers are greedy by default — they grab as much as possible. Add ? to make them lazy — they take the minimum. Classic example: .* in /<.*>/ on '<a><b>' captures '<a><b>', while .*? — only '<a>'. For parsing HTML use a proper parser.
Watch performance
ReDoS
(a+)+ on 'aaaaX' — exponential
Some patterns can hang on millions of backtracking iterations (a ReDoS attack). Nested quantifiers like (a+)+ or (a|a)* are dangerous. Write atomic patterns and test on long inputs. In safety-critical places use RE2 (Go, Google) which has no backtracking.
05
Frequently asked questions
Type the pattern and some sample text — matches highlight as you type and appear in a list with a counter beside it. A broken pattern does not break the page: instead of highlighting you get the engine's own message about what it objected to. Below that, the pattern is broken into tokens with an explanation of each.
How much they swallow. Greedy `.*` takes the longest run that still allows a match, lazy `.*?` takes the shortest. Against `<b>one</b> <b>two</b>`, the pattern `<b>.*</b>` captures everything from the first tag to the last, while `<b>.*?</b>` captures only the first pair. This is the usual cause of a surprising result.
`g` finds every match rather than just the first. `i` ignores case. `m` makes `^` and `$` match at the start and end of each line instead of the whole string. `s` lets the dot match a newline as well. All four are toggled with the buttons next to the pattern field, and the flag string updates with them.
With `\b`, which matches the position between a word character and a non-word one rather than a character itself. `\bcat\b` finds cat but not catalogue or bobcat. The mirror `\B` matches everywhere else. Since word characters here mean letters, digits and the underscore, `\b` behaves oddly around non-Latin text.
Because this editor runs the JavaScript engine and every language ships its own dialect. Lookbehind, named groups, inline flags such as `(?i)` and Unicode property escapes are the usual places where a pattern that works in one engine fails in another. Test in the dialect you will actually run, not only here.
No. Your browser's own regular expression engine does the matching, and neither the pattern nor the test text is transmitted. That also explains a limit worth knowing: matching runs on the main thread, so a catastrophically backtracking pattern against a long sample will freeze the tab rather than time out politely.