Dev Tools
Regex Tester
Test a regular expression against real sample text and see matches highlighted as you type.
Runs entirely in your browser. Nothing you type is sent anywhere.
Learn about regular expressions
What flavor of regex this tests
This runs JavaScript's own regex engine, the same one behind RegExp in any browser or Node.js. It's close enough to other popular flavors like PCRE or Python's re for most everyday patterns, but there are real differences in some corners, like lookbehind support or possessive quantifiers. A pattern that works here is worth double-checking against whatever engine actually runs it in production, especially if that's a different language.
The common flags
g (global) finds every match instead of stopping at the first. i makes the match case-insensitive. m (multiline) makes ^ and $ match the start and end of each line instead of only the whole string. s (dotall) lets . match newline characters too.
Common questions
Why does my pattern match here but fail in my actual code? A different regex engine, like Python's or PCRE, can behave subtly differently even for a pattern that looks the same. It's also worth checking that the same flags are actually applied in both places.
Why did adding .* to my pattern slow everything down or hang? That's likely catastrophic backtracking. Certain patterns, especially nested quantifiers that can match overlapping possibilities, force the engine to try an exponential number of combinations against certain input, which can effectively hang the whole match attempt.
What's the difference between greedy and lazy matching? Greedy matching (the default, like .*) grabs as much as it can and only backs off if it has to. Lazy matching (.*?) grabs as little as possible and expands only when needed. It matters a lot whenever a pattern could technically match more than one valid substring.