Regex Tester

Test a regular expression against your own text with live highlighting, capture groups and a built-in cheat sheet.

Flags

Highlighted matches

Regex cheat sheet
TokenMatches
.Any character except newline
\d \DA digit / a non-digit
\w \WWord character (a-z, 0-9, _) / non-word
\s \SWhitespace / non-whitespace
^ $Start / end of string (or line with m)
\bWord boundary
* + ?0 or more / 1 or more / 0 or 1
{n} {n,m}Exactly n / between n and m times
*? +?Lazy (as few as possible)
[abc] [^abc]Any of a, b, c / none of them
[a-z]Range from a to z
a|ba or b (alternation)
( )Capture group
(?: )Non-capturing group
(?<name> )Named capture group
(?= ) (?! )Lookahead / negative lookahead
\1 \2Backreference to group 1, 2

How to read the results

Type a pattern above and the test string below lights up: every match is highlighted, the count appears next to the label, and the table breaks each match down with its position and any capture groups. Everything recomputes as you type, so you can tighten a pattern one character at a time and watch the highlights shift.

A worked example

Say you want every email in a block of text. The pattern \b[\w.]+@[\w.]+\.\w+\b reads as: a word boundary, one or more word or dot characters, an at sign, the domain, a dot, and the top-level domain. Add capture groups - \b([\w.]+)@([\w.]+)\b - and the table will show the local part and the domain separately for each hit, which is exactly how you would pull them apart in code.

Common gotchas

  • Forgetting the g flag - without it you only ever see the first match.
  • Greedy quantifiers - .* grabs as much as it can. Use .*? when you want the shortest match.
  • Unescaped metacharacters - a literal dot or bracket must be written as \. or \[.

Once your pattern works, put it to use in the find and replace tool, which accepts full regex. For everyday text jobs the word counter and case converter are close at hand too.

Frequently asked questions

What do the regex flags mean?
g (global) finds every match, not just the first. i (ignore case) makes the pattern case-insensitive. m (multiline) makes ^ and $ match at each line break. s (dotall) lets the dot match newlines too. u (unicode) enables full Unicode and \p{...} property escapes.
Why does my pattern only match once?
Without the global flag g, a regex stops after the first match. Tick the g flag to highlight and list every match in the test string. This tool adds g automatically when it needs to scan the whole text, but the match list reflects the flags you choose.
How do I capture part of a match?
Wrap the part you want in parentheses to create a capture group, like (\d{4})-(\d{2}). Each group is numbered from 1 and shown in the match table. Name a group with (?<year>\d{4}) to refer to it by name.
Is this the same regex engine my code uses?
It uses the JavaScript (ECMAScript) regular expression engine built into your browser, so patterns behave exactly as they would in JavaScript or TypeScript. Other languages like Python, PCRE or Java differ in a few features such as lookbehind and named groups.
Does my test data leave the page?
No. The pattern and test string are evaluated entirely in your browser with the native RegExp engine. Nothing is uploaded, so you can safely test against real data.