Regex Tester
Test regular expressions with real-time matching
About Regex Tester
This tool lets you write a JavaScript regular expression, run it against sample text, and see every match and capture group highlighted in real time. It targets the JavaScript regex engine (V8), so the results are exactly what you get in a browser or Node.js — no surprises when you paste the pattern into production code. Useful for building validation rules, extracting structured data from logs, or making sense of a regex you inherited.
Common Use Cases
Frequently Asked Questions
How does JavaScript regex differ from PCRE?
The main practical differences: JS uses (?<name>...) for named capture groups (PCRE uses (?P<name>...)); JS has no recursion or conditional patterns; lookbehind ((?<=...)) requires ES2018 or later. If you are porting a Python or PHP regex, watch for those differences first.
What does each flag do?
g (global) finds all matches instead of just the first. i makes the match case-insensitive. m makes ^ and $ match at each line boundary rather than the whole string. s (dotall) lets . match newline characters. u enables full Unicode mode including \p{} property escapes. d (indices, ES2022) adds start/end offsets for each capture group.
What is the difference between greedy and non-greedy quantifiers?
Greedy quantifiers (*, +, ?) match as much as possible and then backtrack. Non-greedy ones (*?, +?, ??) match as little as possible. For example, <.+> on <a><b> returns one match (<a><b>); <.+?> returns two (<a> and <b>). Use non-greedy when you want the shortest possible match between delimiters.
What are lookahead and lookbehind?
Zero-width assertions that check context without consuming characters. (?=...) is a positive lookahead (the pattern ahead must match). (?!...) is negative. (?<=...) is a positive lookbehind (ES2018+). They are useful when the thing you want to match depends on what surrounds it but you do not want to include the surroundings in the captured text.
When should I use named capture groups?
Any time a pattern has more than one or two groups. Named groups ((?<year>\d{4})-(?<month>\d{2})) make the code self-documenting and let you access results by name (match.groups.year) rather than by brittle index. They also help when a regex changes over time and group indices shift.