Regex Tester

Test regular expressions online for free with live match highlighting, capture groups, and flag support. Private — runs entirely in your browser.

Regex Tester
/ /

Flags: g (all matches), i (ignore case), m (multiline), s (dotall).

User Guide

1

Enter your pattern

Type the expression without surrounding slashes — \d{3}-\d{4} rather than /\d{3}-\d{4}/. The delimiters belong to JavaScript literal syntax, not to the pattern.

2

Set the flags

The flags field takes plain letters. g finds every match rather than stopping at the first, i ignores case, m makes ^ and $ match at line breaks, s lets . match a newline.

3

Paste your test text

Use realistic input, including the awkward cases — empty fields, unusual characters, the row that broke last time. A pattern that only handles tidy data will fail on real data.

4

Read the matches

Matches are listed as found. No matches usually means an unescaped special character: ., +, *, ?, (, [ and $ all have meaning and need a backslash to match literally.

5

Build it up in pieces

Write a fragment, confirm it matches, then extend. Debugging a long expression that matches nothing is far harder than growing one that works at every step.

6

Watch for runaway patterns

Nested quantifiers such as (a+)+ can take exponential time on input that nearly matches. If the page hangs, that is the cause — see the section below.

About the Regex Tester

Regular expressions describe patterns in text. This tool runs yours against sample input using the browser’s own engine, so what you see here is exactly what JavaScript will do — the pattern and flags are passed straight to new RegExp(). The MDN RegExp reference is the authoritative reference for the syntax.

Flavours differ — this one is JavaScript

Regex is not one language. JavaScript, PCRE, Python, Java, Go and POSIX all differ, and a pattern copied from a PHP answer may behave differently or not compile at all. JavaScript notably has no lookbehind in older engines, no recursion, no possessive quantifiers and no atomic groups. If you are testing for a JavaScript or TypeScript codebase this page is exactly right; for another language, verify there too.

The building blocks

Token Matches Example
. Any character except newline a.c → abc, a1c
\d\w\s Digit, word character, whitespace \d{4} → 2026
*+? Zero or more, one or more, optional colou?r → color, colour
{n,m} Between n and m times \d{3,5}
[abc] Any one listed character [aeiou]
^$ Start and end of input ^\d+$
(...) Capture group (\d{4})-(\d{2})
| Either side cat|dog

Greedy versus lazy

The most common source of confusion. Quantifiers are greedy by default: they take as much as they can and then give back only what they must.

Against <b>bold</b> and <i>italic</i>, the pattern <.+> matches the entire string — not the first tag. It runs to the last > it can find. Adding ? makes the quantifier lazy: <.+?> stops at the first > and matches <b> as intended.

When a pattern matches far more than expected, greediness is nearly always the reason.

Catastrophic backtracking

Worth knowing because it can freeze a browser tab or take down a server. When a pattern nests quantifiers — (a+)+b, (\s*)*$, (\w+\s?)+ — the engine may explore an exponential number of ways to split the input before concluding there is no match.

On a 30-character string that can mean billions of steps. This is a real denial-of-service class, usually catalogued as ReDoS. Avoid nesting a quantifier inside a group that is itself quantified, and be specific rather than using .* where a narrower character class would do.

When not to use regex

Regex matches patterns; it does not parse nested structures. HTML, XML and JSON are all recursive, and no regular expression handles arbitrary nesting correctly. Use a real parser: the JSON Formatter for JSON, a DOM parser for HTML.

Email addresses deserve their own warning. The fully compliant expression runs to several thousand characters, and the short ones circulating online all reject valid addresses. Check for an @ with something either side, then send a confirmation email — that is the only validation that actually proves anything.

Privacy

Everything runs in JavaScript inside this page. Nothing you type is transmitted, logged or stored.

Frequently Asked Questions

Why does my pattern match more than I expected?

Quantifiers are greedy by default — they take as much as possible. Against markup, <.+> matches the whole string rather than the first tag. Add a question mark to make it lazy: <.+?> stops at the first closing bracket.

Should I include the slashes around my pattern?

No. Enter the pattern alone and put flags in the separate field. The slashes are JavaScript literal syntax, not part of the expression, and including them makes the tool search for literal slash characters.

What do the flags mean?

g finds every match instead of stopping at the first; i ignores case; m makes ^ and $ match at each line break; s allows the dot to match newlines. They can be combined, for example gim.

Why does my pattern match nothing?

Usually an unescaped special character. The characters . + * ? ( ) [ ] { } ^ $ | and backslash all have meaning in regex. To match one literally, put a backslash before it — \. matches a full stop rather than any character.

Does this work for Python or PHP patterns?

It uses the JavaScript engine, so results match JavaScript and TypeScript exactly. Other flavours differ — JavaScript has no recursion, no possessive quantifiers and no atomic groups — so verify elsewhere if you are targeting another language.

Why did the page freeze on my pattern?

Almost certainly catastrophic backtracking, caused by nesting quantifiers such as (a+)+ or (\w+\s?)+. The engine explores exponentially many ways to split the input before giving up. Avoid quantifying a group that already contains a quantifier.

Can I use regex to parse HTML or JSON?

No. Both are recursive structures and regular expressions cannot handle arbitrary nesting. Use a proper parser — the JSON Formatter for JSON, a DOM parser for HTML.

What is the correct regex for validating an email address?

There is no short one that is correct. The fully compliant expression is thousands of characters, and the popular short versions all reject valid addresses. Check for an @ with content either side, then send a confirmation email.