⚙️

Regex Tester

Test regular expressions against sample text with live match highlighting, flag control and a match count. Free and runs in your browser.

✓ Free forever✓ No signup✓ 100% private — runs in your browser
Regex Tester
Test and debug regular expressions in real time. Highlights matches, shows groups, counts results.
/ /
Quick patterns:
Test String
Replace

Regular expressions are difficult to get right by reading alone — the difference between a pattern that works and one that quietly matches too much is often a single character. Testing against real sample text, with matches highlighted as you type, is the only reliable way to build one.

How to use the Regex Tester

  1. Enter your regular expression
  2. Paste sample text that represents the real data, including edge cases
  3. Set the flags you need — g for all matches, i for case-insensitive, m for multiline
  4. Check the highlighted matches and the match count before using the pattern

The pieces you will use most

  • \d digit · \w word character · \s whitespace. Capitalised versions negate: \D is any non-digit.
  • + one or more · * zero or more · ? zero or one.
  • {3} exactly three · {2,5} between two and five.
  • ^ start of string · $ end of string.
  • [abc] any one of these · [^abc] anything but these.
  • (…) capture group · (?:…) group without capturing.

Greedy matching, the classic trap

Quantifiers are greedy by default — they match as much as possible. Run <.+> against <b>bold</b> and it matches the entire string, not just the opening tag, because .+ consumes everything and then backtracks only enough to find a final >.

Adding ? makes a quantifier lazy: <.+?> matches just <b>. When a pattern matches far more than you expected, greediness is almost always why.

The flags matter too: g finds every match rather than stopping at the first, i ignores case, and m makes ^ and $ match at line boundaries instead of only at the start and end of the whole string.

Catastrophic backtracking, and the patterns that cause it

A regular expression can take exponential time on an input only slightly longer than one it handles instantly. The cause is nested quantifiers over overlapping alternatives, and the result on a server is a denial of service — a single request pinning a CPU core for minutes.

The shape to recognise is a quantifier applied to something that is itself quantified or that can match the same text multiple ways: (a+)+$, (\w+\s?)*$, (.*,)*. Fed a long string of a characters ending in something that fails to match, the engine tries every possible way of dividing the input between the inner and outer quantifier before giving up.

Three defences, in order of preference. Make the inner part unambiguous, so there is only one way to match — replacing (a+)+ with a+ usually does it. Use a possessive quantifier or atomic group where the flavour supports it, which forbids backtracking into the matched section. Or use a flavour that cannot backtrack at all: Go's RE2 and Rust's regex crate guarantee linear time by refusing the features that make it possible.

Test any pattern that will see user input against a long non-matching string before deploying it.

Flavour differences that matter

Regular expression syntax is broadly shared and the edges differ enough to break a pattern moved between languages.

Lookbehind is the most common incompatibility. JavaScript gained it relatively recently, Go's RE2 does not support it at all, and some older engines only allow fixed-width lookbehind.

Named groups are spelled differently: (?<name>…) in JavaScript, .NET and modern PCRE, but (?P<name>…) in Python and Go.

Unicode property escapes such as \p{L} need the u flag in JavaScript and are unsupported in several engines.

\d is not always ASCII. In some engines with Unicode mode on, it matches digits from other scripts too, which is usually not what a validator intends.

Multiline and dot-all are separate flags, and people confuse them. m changes what ^ and $ mean; s makes . match a newline.

This tester runs JavaScript's engine, since it runs in your browser. A pattern verified here is correct for JavaScript and should be re-checked before being moved to Python, Go or a database.

Frequently asked questions

Why does my pattern match more than expected?

Greedy quantifiers. By default + and * take as much as they can. Add ? to make them lazy — .+? instead of .+ — and they take as little as possible.

How do I match a literal dot or question mark?

Escape it with a backslash: \. and \?. The characters . * + ? ( ) [ ] { } | ^ $ \ all have special meaning and need escaping to match literally.

Which regex flavour does this use?

JavaScript's, since it runs in your browser. It is close to PCRE for everyday patterns, but lookbehind support and some Unicode property escapes differ from Python or PHP.

Can I use this to validate email addresses?

You can match the common shape, but fully validating email by regex is not practically possible — the specification permits forms almost nobody implements. Match loosely and confirm by sending a verification email.