1. Home
  2. Tools
  3. Regex Tester

Regex Tester

Try a JavaScript regular expression against your text, see every match and group, and preview a replacement. It runs in your browser.

This tester uses the JavaScript regular expression flavour (the one in your browser). Other languages such as PHP (PCRE), Python or Java differ in some syntax, so check there too.
Matches highlighted

    
  

Your pattern and text are processed in your browser, in a background worker, and are not sent anywhere.

How to use it

  1. Type your pattern between the slashes, without the slashes themselves, for example (\d{4})-(\d{2})-(\d{2}).
  2. Switch flags on or off. g finds every match instead of the first one.
  3. 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.
  4. To preview a substitution, type a replacement. Use $1 for 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: a matches A.
  • 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.

Need a hand with this?

Let our engineers take it from here