Regex Tester

Test regular expressions in real time with live match highlighting.

//

Regex Quick Reference

.Any character (except newline)
\dDigit (0-9)
\wWord character (a-z, 0-9, _)
\sWhitespace
^Start of string / line
$End of string / line
*0 or more
+ 1 or more
?0 or 1 (optional)
(x)Capture group
(?:x)Non-capture group
(?<n>x)Named capture group

How to use the regex tester

  1. Type your pattern in the Pattern field, without the surrounding slashes.
  2. Toggle the flags you need: g, i, m, s.
  3. Paste sample text into the test string box. Matches are highlighted as you type.
  4. Check Match details to see the position of each match and the content of every capture group, including named groups.

A good habit: paste in examples that should notmatch as well as ones that should. Most regex bugs are false positives, the pattern accepting something it shouldn't, and you only see those if you test for them.

Reading a pattern piece by piece

Regular expressions look cryptic until you read them one token at a time. Here's a pattern for an ISO date like 2026-10-16:

^(?<year>\d{4})-(?<month>0[1-9]|1[0-2])-(?<day>0[1-9]|[12]\d|3[01])$
  • ^ and $ anchor the match to the start and end, so x2026-10-16x is rejected.
  • (?<year>\d{4}) is a named group capturing exactly four digits.
  • 0[1-9]|1[0-2] allows 01–09 or 10–12, so month 13 fails.
  • 0[1-9]|[12]\d|3[01] allows 01–31. It will still accept February 31st. Regex is a poor tool for calendar logic; validate the shape here and the date in code.

Paste that pattern above with a few dates and look at the named groups in the match details. It's the quickest way to see how groups work.

Greedy vs lazy matching

Quantifiers like * and + are greedy: they grab as much as they can, then give characters back only if the rest of the pattern needs them. Against the text <b>one</b> and <b>two</b>, the pattern <b>.*</b> matches the whole line, from the first tag to the very last. Adding a ? makes the quantifier lazy: <b>.*?</b> stops at the first closing tag and gives you two separate matches. An even better fix is often a negated class, <b>[^<]*</b>, which says exactly what's allowed in between.

JavaScript specifics worth knowing

  • Lookbehind ((?<=\$)\d+) works in all current browsers. It was the last major engine gap, closed when Safari added support in 2023.
  • Named groups use (?<name>…). Python historically used (?P<name>…), which JavaScript rejects.
  • No possessive quantifiers or atomic groups (a++, (?>…)). Patterns copied from Java or PCRE that use them will throw an error here.
  • \d means ASCII digits only, even with the u flag. Use \p{Nd} with u if you need other numeral systems.

Looking for ready-made patterns? Our regex cheat sheet has fifteen common ones (emails, URLs, phone numbers, whitespace cleanup), each explained and tested against the edge cases that break the naive version.

Frequently asked questions

Which regex flavor does this tester use?+

JavaScript's, as implemented by your browser. It's the same engine your front-end code and Node.js use. Most everyday syntax is shared with Python, Java, PCRE and .NET, but details differ: lookbehind support, possessive quantifiers, and how named groups are written.

Why does my pattern match in the tester but not in my code?+

Usually escaping. In a JavaScript string, "\d" must be written as "\\d" when passed to new RegExp(), whereas here you type the pattern as it would appear between slashes. Also check the flags: a missing g or m flag changes the result.

What do the g, i, m and s flags do?+

g finds every match instead of stopping at the first. i ignores case. m makes ^ and $ match at the start and end of each line instead of the whole text. s lets the dot match newline characters too.

Why does my regex freeze the page?+

Some patterns, typically nested quantifiers like (a+)+ or (.*)*, can take exponential time on input that almost matches. This is called catastrophic backtracking. Make the inner part more specific, or rewrite the pattern so each character can only be matched one way.

Is it safe to test patterns against real data?+

Yes. Matching runs entirely in your browser; the text you paste is never uploaded. That's useful when the test string is a production log or a customer export.

Last updated October 16, 2026