Regex Tester

Test JavaScript regular expressions against your text: every match highlighted and listed with its index and capture groups, a replace and split preview, and what each flag changed.

Tester Web & Dev Updated Oct 3, 2026
Learn how this works
How to Use
  1. Type the pattern between the slashes and the flags after them, or tick the flag boxes (g, i, m, s, u, y).
  2. Paste your test text. Matches are highlighted as you type, and the match table lists each one with its index, length and capture groups.
  3. Choose Replace to preview String.replace with $1, $<name> and $&, or Split to see the array String.split returns.
  4. Read Show Work: every match with its groups, and what each flag changed — the pattern is run again without the flag and the counts are compared.
  5. A pattern that runs for more than 2 seconds is stopped and reported as too slow instead of freezing the page. Press Railroad diagram to see how the same pattern is built.
Pattern
JavaScript
/ /
0 chars
Railroad diagram →
Presets
Matches
Matches
—
Capture groups
—
First match
—
Run time
—

Worked Example

Find the phone numbers in “Call 555-1234 or 867-5309, or try 888-0000.” with /\b(\d{3})-(\d{4})\b/g.

\b is a word boundary, (\d{3}) captures three digits as group 1, - is a literal hyphen and (\d{4}) captures four digits as group 2. With the g flag the search carries on after each match:
Match 1: index 5, “555-1234”, $1 = 555, $2 = 1234.
Match 2: index 17, “867-5309”, $1 = 867, $2 = 5309.
Match 3: index 34, “888-0000”, $1 = 888, $2 = 0000.
Replacing with $2-$1 gives “Call 1234-555 or 5309-867, or try 0000-888.” Without the g flag only the first match is replaced: “Call 1234-555 or 867-5309, or try 888-0000.”

The common mistake: a greedy .+. To pick the tags out of “<b>bold</b> and <i>it</i>”, /<.+>/g looks right but makes 1 match of all 25 characters: .+ runs to the end of the text, then backs off only as far as the last >. The lazy /<.+?>/g stops at the first > it can and makes 4 matches — <b> at 0, </b> at 7, <i> at 16 and </i> at 21. /<[^>]+>/g gives the same 4 and cannot run past a > at all.

Show Work

Enter a pattern and some text to see each match, its groups and what each flag changed.

Syntax Reference

Character classes
\d  \w  \s  .  [abc]  [^abc]
Digit, word character (A–Z a–z 0–9 _), whitespace, any character but a line break, one of a set, none of a set
Quantifiers
*  +  ?  {3}  {2,}  {2,5}
0 or more, 1 or more, 0 or 1, exactly 3, 2 or more, 2 to 5 — greedy: as many as possible
Lazy quantifiers
*?  +?  ??  {2,5}?
The same counts, but as few as possible
Anchors
^  $  \b  \B
Start, end (of each line with m), word boundary, not a boundary — positions, not characters
Groups
( )  (?: )  (?<name> )  \1  \k<name>
Capture, group without capturing, named capture, back-references
Look-around
(?= )  (?! )  (?<= )  (?<! )
Followed by, not followed by, preceded by, not preceded by — checked but not consumed
Replacement tokens
$1  $<name>  $&  $`  $'  $$
Group 1, a named group, the whole match, text before it, text after it, a literal $
Flags
g i m s u v y d
All matches, ignore case, multiline, dot-all, unicode, unicode sets, sticky, group indices

Common patterns

Email (loose)
[\w.%+-]+@[\w.-]+\.[A-Z]{2,}
With the i flag. Good enough for form checks; the full RFC 5322 grammar is not worth a regex.
URL
https?:\/\/\S+
Plain http and https links up to the next space.
IPv4 (loose)
\b(?:\d{1,3}\.){3}\d{1,3}\b
Four groups of 1–3 digits. Also accepts 999.1.1.1, so check each part is 0–255 in code.
ISO date
\d{4}-\d{2}-\d{2}
YYYY-MM-DD.
Hex colour
#(?:[0-9a-fA-F]{3}){1,2}\b
#fff and #1a2b3c, but not the 5-digit #12345.
UUID
[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
The standard 36-character form; add i for capitals.
Blank lines
^\s*$
With the m flag: empty or whitespace-only lines.
Whole word
\bword\b
“word” but not “password” or “words”.

A Brief History of Regular Expressions

Regular expressions began as mathematics. Stephen Kleene described “regular events” in a 1951 RAND Corporation memorandum, published in 1956, as a way to describe what simple machines — finite automata — can recognise. The star in a* is still called the Kleene star.

Ken Thompson turned the notation into a working search. His 1968 paper “Regular Expression Search Algorithm” compiled patterns into machine code for the QED editor, and the same idea went into the Unix editor ed and then grep, whose name is the ed command g/re/p: globally search for a regular expression and print. Henry Spencer’s regex library (1986) spread the syntax further, Larry Wall’s Perl (1987) added lazy quantifiers, look-ahead and non-capturing groups, and Philip Hazel’s PCRE (1997) carried the Perl style into other languages.

JavaScript took the Perl style in 1997 and standardised it in ECMAScript 3 (1999). ECMAScript 2018 added lookbehind, named groups, the s flag and \p{…} classes; the d flag followed in 2022 and the v flag in 2024. Perl-style engines backtrack, which is what makes back-references possible and what makes catastrophic patterns possible too; Russ Cox’s RE2 (2010) gives up back-references to guarantee time linear in the input, which is why it is used for untrusted patterns.

About This Tool

This tester runs your pattern with your browser’s own JavaScript RegExp engine, so a match here is a match in your code. It highlights every match in the text, lists each one in a table with its index, length and capture groups, and previews String.replace and String.split exactly as JavaScript returns them. Show Work goes further than a highlight: it runs the pattern again without each flag you set and tells you what that flag changed.

Matching runs in a background worker. If a pattern takes more than 2 seconds — the sign of catastrophic backtracking — the worker is stopped and you get an explanation instead of a frozen tab. Test text up to 200,000 characters and up to 10,000 matches are handled. Nothing is uploaded; the pattern and text never leave your browser.

To see how a pattern is built rather than what it matches, open it in the Regex Railroad Diagram: the Railroad diagram link above carries your pattern and flags across.

Related tools: Regex Railroad Diagram, Text Diff Tool, and JSON Formatter.

Frequently Asked Questions

Which regex flavour does this test?

JavaScript (ECMAScript), run by your browser’s own RegExp engine, so the result is exactly what your code will get. That includes lookbehind (?<=…), named groups (?<name>…), Unicode property escapes \p{L} with the u flag, and the s flag (all ES2018). PCRE-only features — possessive quantifiers a++, atomic groups, recursion, inline comments — are syntax errors here.

What does each flag do?

g finds every match instead of stopping at the first; i ignores case; m makes ^ and $ match at every line break; s lets . match line breaks; u reads whole Unicode code points and enables \p{…}; y (sticky) makes each match start exactly where the last ended. With ^\w+ on three lines, the gm flags give 3 matches and g alone gives 1 — Show Work runs that comparison for whatever flags you set.

How do capture groups and replacement tokens work?

Each pair of parentheses captures what it matched: the first is $1, the next $2. A named group (?<y>\d{4}) is written back as $<y> (not ${y}, which JavaScript leaves as plain text). $& is the whole match and $$ a dollar sign. (?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2}) with $<d>/$<m>/$<y> turns 2026-10-03 into 03/10/2026.

Why does .* match too much?

Quantifiers are greedy: they take as much as they can and only give back what the rest of the pattern needs. On bold and it, <.+> makes 1 match of all 25 characters, from the first < to the last >. The lazy <.+?>, or the tighter <[^>]+>, makes 4 matches: each tag on its own.

Why does my regex run forever?

Catastrophic backtracking. In ^(a+)+$ a run of a’s can be split between the inner and outer + in exponentially many ways, and when the match fails (a ! at the end) the engine tries them all: each extra a roughly doubles the time, so 26 a’s take about 0.4 seconds and 40 would take hours. This tester runs your pattern in the background and stops it after 2 seconds. The fix is to remove the nested repeat: ^a+$.

How do I use the Regex Tester?

Just type your numbers. The answer shows up right away — there is no button to press. Change anything and it updates by itself.

Do I need to install or sign up for anything?

Not at all — it runs in the browser with nothing to install and no account. After it loads once, it even works without an internet connection.

Is my information private?

Yes. Everything happens in your browser. Nothing you type is sent to a server or saved anywhere.

Common Use Cases

Validating form input

Check a postcode, phone or email pattern against 10 good and 10 bad samples, one per line with the m flag, before it goes into the form.

Extracting data from logs

Pull IP addresses, status codes or timestamps out of a pasted log: the match table gives each one’s index and groups, and Copy matches puts them one per line.

Search and replace in code

Rehearse a refactor such as (\w+)\.then\( → await $1( on a sample before running it across a codebase in your editor.

Reformatting dates and numbers

Turn ISO dates into day/month/year with named groups: 2026-09-28 becomes 28/09/2026.

Splitting messy text

Split on [,;]\s* to turn “one, two;three” into the three-item array ["one","two","three"].

Finding a slow pattern

Paste a pattern that hangs a server and see it stopped here at 2 seconds, then rewrite the nested quantifier until it finishes in under 1 ms.

Last updated: