Regex tester

Test JavaScript regular expressions with live match highlighting, capture groups and match positions. Supports the d, g, i, m, s, u, v and y flags.

Processed locally in your browser
Loading tool…

About Regex tester

The regex tester runs a regular expression against your test text and highlights every match as you type. A table lists each match with its starting index and capture groups, and the status bar shows the total count, so you can see exactly what a pattern does before putting it in code.

Patterns use the JavaScript (ECMAScript) regex engine built into your browser, the same flavor used by String.match, replace and RegExp in Node.js and front-end code. Matching runs in a background worker with a 1.5-second limit, so a pattern with catastrophic backtracking stops with a message instead of freezing the page.

How to use Regex tester

  1. Enter your pattern in the Pattern field without surrounding slashes, for example [A-Z]\w+.
  2. Set the flags, such as i or m; g is filled in by default.
  3. Type or paste the text to test in the Test string box, or open or drop a text file.
  4. Read the highlighted matches and the table of indexes and capture groups below them.

Features

  • Highlights every match in the test string as you edit the pattern, flags or text.
  • Counts up to 1,000 matches and lists the first 200 in a table with index and capture groups.
  • Accepts the d, g, i, m, s, u, v and y flags and ignores other letters.
  • Finds all matches even when the g flag is not set.
  • Stops any pattern that runs longer than 1.5 seconds, protecting the page from runaway backtracking.
  • Supports lookbehind, named groups and Unicode property escapes such as \p{L} with the u flag.

Common uses

  • Building a validation pattern for email addresses, postal codes or order IDs.
  • Writing a pattern to extract fields from log lines.
  • Debugging a regex that matches too much or too little.
  • Checking a pattern found online before using it in JavaScript code.

Tips

  • Escape special characters such as . * + ? ( ) [ ] { } | ^ $ and \ with a backslash when you want to match them literally.
  • Empty matches are shown as ∅ in the table. If you see many of them, your pattern can match zero characters, often because a * was used where a + was intended.

Frequently asked questions

Which regex flavor does this tester use?

JavaScript (ECMAScript), as implemented by your browser. Most syntax is shared with PCRE, Python and Java, but there are differences: JavaScript has no possessive quantifiers or atomic groups, for example. Test patterns meant for other languages in a tester for that language.

What do the regex flags mean?

g finds all matches, i ignores case, m makes ^ and $ match at line breaks, s lets . match newlines, u enables Unicode mode, v enables the newer Unicode sets mode, y matches only at the current position, and d records match indices. This tester always lists all matches.

Why does my pattern time out?

Some patterns, such as (a+)+$ tested against a long run of a’s followed by another character, take exponential time because the engine tries every way of splitting the input. This is catastrophic backtracking. Make nested quantifiers unambiguous or anchor the pattern so the engine fails faster.

Do I need to include the slashes around the pattern?

No. Enter only the pattern, such as \d{3}-\d{4}, and put the flags in the Flags field. Slashes belong to JavaScript’s regex literal syntax, not to the pattern, so a slash inside the pattern does not need escaping here.

How are capture groups shown?

The Groups column lists each capture group’s value in order, separated by commas. Named groups appear in their position like numbered ones. A group that did not take part in a match is shown as a dash.

Can I test find and replace?

No. This tester shows matches and groups only. To replace text with a regular expression, use the Regex mode of the Find and replace tool, which supports $1-style references to capture groups.

Is my input uploaded?

Tools run in your browser. Files, text and results are not uploaded to our servers and are cleared when you leave the tool.

Your privacy comes first

Tools run in your browser. Files, text and results are not uploaded to our servers and are cleared when you leave the tool.

Find your next tool
↑ ↓ · Enter ↵Esc · Close search