DevTools Pro · All tools · About

Regex Tester

About the Regex Tester

This regex tester runs JavaScript regular expressions against your text and highlights every match as you type. It lists numbered and named capture groups, lets you toggle flags, and previews replacements, so you can debug a pattern before it goes into your code.

JavaScript regex flags explained

g (global) finds every match instead of stopping at the first. i ignores case. m (multiline) makes ^ and $ match at each line break, not just the start and end of the whole text.

s (dotAll) lets . match newline characters. u enables full Unicode handling, needed for emoji and \p{...} property escapes. y (sticky) only matches at the current position, which is mostly useful in tokenizers.

Capture groups and replacements

Parentheses capture part of a match. In (\d{4})-(\d{2}), group 1 is the year and group 2 the month. Named groups make patterns easier to read: (?<year>\d{4}).

In Replace mode, refer to groups with $1, $2 or $<name>, and to the whole match with $&. For example, the pattern (\w+)@(\w+) with replacement $2:$1 turns alice@example into example:alice.

Catastrophic backtracking

Nested quantifiers such as (a+)+$ can take exponential time on input that almost matches, freezing a browser tab or a server (a ReDoS vulnerability). This tester runs matching in a background worker and stops any run that takes longer than 1.5 seconds, then tells you the pattern is too slow.

If you hit that limit, remove nested quantifiers or make alternatives mutually exclusive, for example a+$ instead of (a+)+$.

How to Use the Regex Tester

  1. Enter your pattern in the Regular expression field without the surrounding slashes, then toggle the flags you need (g, i, m, s, u or y). Click Load Example to start from a working sample.
  2. Paste the text to test into the Test String box. Matches are highlighted instantly and listed under Match Details with their numbered and named groups.
  3. Turn on Replace mode and enter a replacement such as $1 or $<name> to preview the result, then copy or download it. Clear empties the pattern, test string and replacement.

Regex Tester Examples

Swap parts of an email with named groups

Pattern (?<word>\w+)@(\w+)\.com, flags g, replacement $<word> at $2.

Input:

Contact alice@example.com or bob@test.com today.

Output:

Contact alice at example or bob at test today.

Reformat dates

Pattern (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}), flags g, replacement $<day>/$<month>/$<year>.

Input:

Released 2026-11-19, patched 2026-12-01.

Output:

Released 19/11/2026, patched 01/12/2026.

Match the first word of every line

Pattern ^\w+, flags gm, replacement [$&]. Without the m flag only the first line matches.

Input:

alpha one
beta two
gamma three

Output:

[alpha] one
[beta] two
[gamma] three

Common Errors

The pattern matches the slashes themselves, e.g. /\d+/ highlights /5/
Type the pattern without the /.../ delimiters. Flags are set with the buttons, not after a closing slash.
Only the first match is highlighted
Turn on the g flag. Without it, JavaScript stops after the first match.
\p{L} or other Unicode property escapes find nothing
Add the u flag. Without it, \p{L} is not treated as a Unicode property.
Invalid regular expression: Unterminated group (or Unterminated character class)
A ( or [ is not closed. Add the closing character, or escape it with a backslash when you mean it literally.
Timed out: matching took longer than 1.5s
The pattern probably backtracks catastrophically, for example (a+)+$. Remove nested quantifiers or make the alternatives mutually exclusive.

Frequently Asked Questions

Which regex flavor does this use?
JavaScript (ECMAScript), the same engine your browser and Node.js use. Most syntax also works in PCRE, Python and Java, but features like possessive quantifiers and some lookbehind forms differ.
Why does my pattern only find one match?
Turn on the g flag. Without it, JavaScript stops after the first match.
Do I need to escape slashes?
No. Type the pattern without the surrounding /.../ delimiters. Inside the pattern, escape special characters like ., ?, ( and \ with a backslash when you mean them literally.
Why does ^ only match the first line?
By default ^ and $ mean the start and end of the whole text. Enable the m flag to make them match at every line.
Is my text sent to a server?
No. Matching runs in your browser, in a Web Worker on your device. Your pattern and test text are never uploaded.

Related tools