Skip to content

← All tools

Free online tool

Regex tester for JavaScript

Type a pattern, paste some text and see every match highlighted straight away, with a list of matches, a table of capture groups, a find-and-replace preview and a split preview. This page tests the JavaScript flavour of regular expressions, so check the differences before you copy a pattern into Python, Java or PHP. Your text stays in this page and is never uploaded.

This tests the JavaScript flavour only

Regular expressions differ between languages. Python, Java, PCRE (PHP, grep -P) and .NET differ from JavaScript in lookbehind rules, named-group syntax ((?<name>...) here, (?P<name>...) in Python), possessive quantifiers and atomic groups (not in JavaScript), and flags. A pattern that works here can fail elsewhere and the other way round.

Flags

Supports $1, $<name>, $& (the match), $` (text before) and $' (text after). Use $$ for a dollar sign.

Limits: pattern 2,000 characters, test string 1,000,000 characters, up to 5,000 matches listed. Everything runs in this page and nothing is uploaded.

Start from an example

These are simplified examples for learning, not validators. Real email addresses, web addresses and dates have many more rules, so do not rely on them to check user input.

How it works

  • •The pattern runs through the same regular-expression engine your browser uses for JavaScript, so the result matches what new RegExp(pattern, flags) gives in your own code. Other languages can behave differently: lookbehind rules, named-group syntax, possessive quantifiers and atomic groups are the usual surprises.
  • •Matching happens in a background worker, not on the page itself. If a pattern takes longer than the time you choose (1 second by default), the worker is stopped and you see a warning instead of a frozen tab. Patterns such as (a+)+$ on a long run of a's are the classic cause: the engine tries exponentially many ways to match.
  • •Without the g flag you get the first match only. With g you get all of them, and empty matches (for example from a* or \b) are listed with a marker and do not loop forever. The d flag adds the start and end of every group.
  • •Replace uses JavaScript's own rules: $1 is a numbered group, $<name> a named group, $& the whole match, $` the text before it and $' the text after it. Split shows what String.split gives, including any capture groups, which are added to the parts.
  • •The examples for emails, web addresses, dates, IPv4 addresses and hex colours are deliberately simplified to teach the syntax. They accept things that are not valid and reject some that are, so they are not validators.
  • •To keep the page responsive the pattern can be up to 2,000 characters, the text up to 1,000,000 characters, and at most 5,000 matches are listed.

Questions

Will my pattern behave the same in Python, Java or PHP?
Not always. This page runs JavaScript regular expressions. Python and Java write named groups differently (Python uses (?P<name>...)), PCRE and Java support possessive quantifiers and atomic groups that JavaScript lacks, and lookbehind support and flags vary by language. Test in the language you will actually use before you rely on a pattern.
Why was my pattern stopped?
It probably backtracks catastrophically: with nested repeats like (a+)+ or overlapping alternatives like (a|a)*, a failing match makes the engine try an exponential number of paths. Make the alternatives exclusive, remove the nested repeat, or anchor the pattern. You can also raise the time limit, but a pattern that needs it will be slow in real code too.
What do the flags do?
g finds all matches, i ignores case, m makes ^ and $ work on every line, s lets the dot match line breaks, u turns on Unicode mode (needed for \p{L} and for treating emoji as single characters), y matches only at the exact position, d reports group positions, and v is a newer Unicode mode that appears only when your browser supports it.
Is my text uploaded or saved?
No. The pattern and text are sent only to a background worker inside this page, nothing goes over the network and nothing is stored. Refreshing the page resets everything to the sample.

Related tools