How to use it
- Type your pattern between the slashes, without the slashes themselves, for example
(\d{4})-(\d{2})-(\d{2}). - Switch flags on or off. g finds every match instead of the first one.
- Paste or type your test text. Every match is highlighted as you type, and the table lists each match with its position and capture groups. Named groups, such as
(?<year>\d{4}), are shown by name. - To preview a substitution, type a replacement. Use
$1for the first group,$<name>for a named group and$&for the whole match.
What the flags mean
- g global: find all matches, not just the first.
- i ignore case:
amatchesA. - m multiline:
^and$match at the start and end of every line. - s dotAll:
.also matches a newline. - u unicode: treats the pattern and text as Unicode code points and enables
\p{…}property escapes. - y sticky: match only at the current position.
Runaway patterns
Some patterns, such as (a+)+$ tested against a long string of as that ends in another character, take exponentially longer as the text grows. This is called catastrophic backtracking, and in a normal web page it would freeze the tab. The tester runs your pattern in a background worker and stops it after 1.5 seconds, then tells you so. If you see that message, make the pattern more specific, avoid nested repeats on the same characters, or shorten the test text.
Results are limited to the first 1,000 matches, and the test text to 200,000 characters.
Related tools
URL encoder, decoder and parser, JSON formatter and viewer and UUID generator.
Frequently asked questions
JavaScript’s, as built into your browser. It supports named groups, lookahead and lookbehind in current browsers, but not some features from PCRE (PHP, Perl) such as atomic groups, possessive quantifiers or recursion. A pattern that works here may need small changes in another language.
No. The pattern runs in a worker inside your browser. Nothing is sent to CodeROG or anyone else.
The pattern probably backtracks heavily on your text. The tester stops it after 1.5 seconds so the page keeps working. Nested quantifiers like (a+)+ or overlapping alternatives are the usual cause.
Turn on the g flag. Without it, a regular expression stops after the first match.
The slashes in the box are only for display. Type the pattern as it would appear between the slashes in /pattern/flags. In a JavaScript string you would also need to double each backslash; here you should not.