Regex tester
Write a JavaScript regular expression and see every match highlighted as you type.
tool 04 of 12 []
all shortcuts ?
Uses your browser's own RegExp engine (ECMAScript), in a background worker. A run that takes longer than 1 second is stopped, so a pattern that backtracks catastrophically cannot freeze this tab.
How to use it
- Type your pattern without the surrounding slashes, and put flags (g, i, m, s, u, y, d, v) in the Flags box.
- Matches are highlighted in the test string and listed below with their position, numbered groups and named groups.
- Add a replacement to preview a String.replace result. Use $1 for a numbered group, $<name> for a named group and $& for the whole match.
- Without the g flag only the first match is reported, exactly as in JavaScript.
Examples
Select an example to load it into the tool.
- Emails
(?<user>[\w.]+)@(?<host>[\w.-]+) - ISO dates
(\d{4})-(\d{2})-(\d{2}) - Invalid (unclosed group)
(abc
Frequently asked questions
Which regex flavor is this?
JavaScript (ECMAScript). It is close to PCRE but not identical: there is no possessive quantifier or atomic group, lookbehind is supported in modern browsers, and named groups use (?<name>...). Test patterns for Python or PCRE in that language.
What do the flags mean?
g finds all matches, i ignores case, m makes ^ and $ match at line breaks, s lets . match newlines, u enables full Unicode, y sticks to lastIndex, d records match indices and v enables set notation (newer browsers).
Why does my pattern match an empty string everywhere?
Patterns such as a* can match zero characters. The tester advances one character after an empty match to avoid looping, and empty matches are listed but not highlighted.
Is my test text uploaded?
No. The pattern and text stay in your browser and nothing is sent over the network.
What is catastrophic backtracking?
Nested quantifiers such as (a+)+ can take exponential time on certain inputs. If the page hangs, reload it and rewrite the pattern with anchors or atomic-style constructs such as lookahead with a backreference.