How to use the regex tester
- Type your pattern between the slashes. Don't add the slashes yourself.
- Tick the flags you need.
gfinds every match; without it only the first match is found. - Paste the text you want to search. Matches are highlighted on the right, and listed below with their capture groups.
- Optionally, type a replacement to preview a search-and-replace.
The tester uses the JavaScript (ECMAScript) regex flavor, the same one used by browsers and Node.js. Most simple patterns work the same in Python, Java, PHP and other languages, but some features (like lookbehind or named group syntax) can differ.
New to regex? Open Load an example… for ready-made patterns such as email addresses, URLs, HEX colors, dates with named groups and repeated words. Copy regex and Copy result take the pattern or the replaced text.
Regex cheat sheet
| Token | Meaning |
|---|---|
| . | Any character except a line break (any character with the s flag) |
| \d \w \s | A digit, a word character (letter, digit, _), a whitespace character |
| \D \W \S | The opposite: not a digit, not a word character, not whitespace |
| [abc] [^abc] [a-z] | One of a, b or c · anything except a, b, c · any letter from a to z |
| ^ $ | Start and end of the text (of each line with the m flag) |
| \b | A word boundary, e.g. \bcat\b matches "cat" but not "category" |
| * + ? | 0 or more · 1 or more · 0 or 1 of the previous item |
| {3} {2,} {2,5} | Exactly 3 · 2 or more · between 2 and 5 |
| *? +? | Lazy versions: match as little as possible |
| (abc) | Capture group, available as $1 in replacements |
| (?<name>abc) | Named capture group, available as $<name> |
| (?:abc) | Group without capturing |
| a|b | a or b |
| (?=abc) (?!abc) | Followed by abc · not followed by abc (lookahead) |
| (?<=abc) (?<!abc) | Preceded by abc · not preceded by abc (lookbehind) |
| \1 | Backreference: the same text as group 1 matched |
| \. \* \\ | Escape a special character to match it literally |
FAQ
Why does the tester say my pattern "took too long"?
Some patterns, such as (a+)+$, can take exponentially long on certain inputs. This is called catastrophic backtracking. The tester stops after 1.5 seconds instead of freezing your browser. Rewriting nested quantifiers usually fixes it.
Is my text sent anywhere?
No. Matching runs entirely in your browser.
How do I match whole lines?
Wrap the pattern in ^ and $ and tick the m flag, so they mean the start and end of each line instead of the whole text. For example, ^\d+$ finds lines that contain only digits.
Why does my pattern miss text across line breaks?
The dot doesn't match a line break by default. Tick the s flag, or use [\s\S], which matches any character including line breaks.