How to test a regular expression
- Type your pattern between the slashes and choose flags.
- Paste test text. Matches are highlighted live and listed with their position and capture groups.
- Optionally enter a replacement to preview a find-and-replace.
Regex cheat sheet
.any character ·\ddigit ·\wword character ·\swhitespace*0 or more ·+1 or more ·?optional ·{2,5}between 2 and 5^start ·$end ·\bword boundary[abc]one of ·[^abc]none of ·a|beither(…)capture group ·(?:…)non-capturing ·(?<name>…)named group(?=…)lookahead ·(?<=…)lookbehind
Avoid catastrophic backtracking
Nested quantifiers like (a+)+ can take exponential time on certain input and freeze a page or server. Prefer specific character classes over .*, and anchor patterns where possible.
Related: Diff Checker, JSON Formatter.
Understanding flags
- g (global): find all matches instead of stopping after the first.
- i (ignore case):
/hello/ialso matches “Hello” and “HELLO”. - m (multiline):
^and$match at the start and end of each line, not just the whole text. - s (dotAll):
.also matches line breaks. - u (unicode): treats emoji and other characters outside the basic plane as one character and enables
\p{…}property escapes like\p{L}for any letter. - y (sticky): only matches starting exactly at the current position.
Greedy vs. lazy
Quantifiers like * and + are greedy: they match as much as possible. In the text <b>a</b><b>c</b>, the pattern <b>.*</b> matches everything from the first tag to the last. Adding a question mark makes them lazy: <b>.*?</b> matches each bold section separately.
Using your pattern in other languages
In JavaScript you can use the pattern directly as /pattern/flags. In Python, use a raw string r"pattern" with re.findall; Python uses (?P<name>…) for named groups. In Java and C#, remember to double every backslash inside string literals. Lookbehind and Unicode property escapes are supported in most modern engines, but not in every older one.
Validate, don’t over-validate
Regular expressions are great for finding and extracting text, but trying to fully validate complex formats like email addresses with one pattern usually rejects valid input. Use a simple pattern to catch obvious mistakes and rely on a confirmation step for the rest.
Testing replacements
The replacement box previews a find-and-replace on your test text. Use it to check reformatting before running it on real data, for example turning dates from 2026-11-12 into 12/11/2026 with the pattern (\d+)-(\d+)-(\d+) and the replacement $3/$2/$1.
Frequently asked questions
Which regex flavor does this use?
It uses your browser’s JavaScript (ECMAScript) engine, which supports lookbehind, named groups, Unicode property escapes and the s (dotAll) flag. Most patterns also work in Python, Java and PCRE with minor differences.
Why does my pattern only find one match?
Turn on the g (global) flag to find all matches instead of only the first one.
How do I use capture groups in the replacement?
Use $1, $2… for numbered groups, $<name> for named groups and $& for the whole match.