Skip to content

Regex Tester

Test a JavaScript regular expression live: highlighted matches, groups, flags and replace.

Pattern and text

Flags
0 characters
Cheat sheet
.
Any character except a line break (all with the s flag)
\d \w \s
Digit, word character, whitespace
\b
Word boundary
^ $
Start and end of the text (of each line with m)
[abc] [^abc]
One of, or none of, these characters
a* a+ a?
Zero or more, one or more, optional
a{2,5}
Between 2 and 5 times
a*?
As few as possible (lazy)
(abc)
Capture group
(?<name>abc)
Named capture group
(?:abc)
Group without capturing
a|b
Either a or b
(?=a) (?!a)
Followed by / not followed by
(?<=a) (?<!a)
Preceded by / not preceded by
$1 $<name>
In a replacement: insert a group

Matches

Matches are highlighted here. Patterns run in a background worker, so a slow one can’t freeze the page.

Runs in your browser — nothing you enter leaves this device.

About this tool

What it does

Regular expressions describe patterns in text — email addresses, dates, log lines, the part of a URL you want to extract. This tester runs your pattern with your browser’s own JavaScript regex engine, the same one Node.js and every modern browser use, so what matches here matches in your code. As you type it highlights each match in the test text, lists every match with its position and capture groups (including named groups), and can preview a replace with $1 or $<name> references. Patterns run in a background worker with a time limit, so a runaway pattern is stopped instead of freezing the page.

How to use it
  1. Type the pattern between the slashes, without surrounding / characters.
  2. Turn flags on or off: g for all matches, i to ignore case, m for line-by-line ^ and $, s so the dot matches newlines, u for Unicode.
  3. Paste the text to test. Matches are highlighted and listed with their groups.
  4. Turn on Replace to preview a substitution, using $1, $2 or $<name> for groups.
  5. Open the cheat sheet for a reminder of the common syntax, or try the example.
Limits and your data
  • This is JavaScript regex. Patterns from Python, PCRE (PHP), Java or .NET mostly work, but features such as possessive quantifiers, atomic groups, \A and \Z, inline (?i) modifiers and recursion are not supported and show as errors.
  • Test text is limited to 200,000 characters, and the first 1,000 matches are listed.
  • A pattern that runs for more than 1.5 seconds is stopped. That protects the page, but in your own code the same pattern could hang a server — rewrite it rather than raising a limit.
  • The replace preview uses JavaScript’s String.replace rules; other languages use different group syntax (such as \1).
  • Matching happens in a Web Worker on your device. Your pattern and test text are never sent anywhere or saved, so it’s safe to test against real log lines.

Questions

Why does my pattern only find the first match?

Without the g flag, a JavaScript regex stops after one match when replacing. This tester always lists every match, but the replace preview follows the g flag so it behaves like your code.

What is catastrophic backtracking?

Patterns like (a+)+$ or (x|x)* can try an exponential number of ways to match before failing. On a long string that takes seconds or years. Make repeated parts unambiguous, or anchor and limit them.

How do I match across multiple lines?

Use the m flag so ^ and $ match at line breaks, and the s flag if . should also match newline characters.

How do I match Hindi or other scripts?

Turn on the u flag and use Unicode property escapes, such as \p{Script=Devanagari}+ for Devanagari words or \p{L}+ for letters in any language.

Is there a regex to validate every email address?

No practical one. Use a simple pattern to catch typos, then confirm the address by sending an email to it.