More
More
Regex Tester
Test regular expressions with live matches.
Free. Runs in your browser: nothing you enter or open is uploaded.
Matches appear here as you type.
Cheat sheet
| . | Any character except a line break (with the s flag, line breaks too) |
|---|---|
| \d \w \s | A digit, a word character (letter, digit, _), a space or other white space |
| \D \W \S | The opposite: not a digit, not a word character, not white space |
| [abc] [^abc] [a-z] | One of the listed characters, none of them, or a range |
| ^ $ | Start and end of the text (of each line with the m flag) |
| \b | A word boundary |
| * + ? | Zero or more, one or more, zero or one of the previous item |
| {3} {2,5} {2,} | Exactly 3, between 2 and 5, 2 or more |
| *? +? | Lazy: match as few as possible |
| (abc) (?:abc) | A capturing group, a group that does not capture |
| (?<name>abc) | A named group, used as $<name> in the replacement |
| a|b | a or b |
| (?=x) (?!x) | Followed by x, not followed by x |
| (?<=x) (?<!x) | Preceded by x, not preceded by x |
| \1 \k<name> | The same text a group matched earlier |
| $& $1 $<name> | In the replacement: the whole match, group 1, a named group |
This uses your browser's JavaScript regular expression engine, so the results match what JavaScript code will do. Other languages (PCRE in PHP, Python's re) agree on most patterns but differ on some details. Matching runs in a background worker that is stopped after 1.5 seconds, so a pattern that backtracks endlessly cannot freeze the page, and at most 1,000 matches are listed.
How to use it
- Type a pattern without the surrounding slashes and tick the flags you need.
- Paste the text to test. Matches are highlighted as you type, with every group listed in the table.
- Try a replacement using $1 or $<name> and copy the result.
Questions
Why does my pattern only find the first match?
Without the g flag, a JavaScript regular expression stops at the first match. Tick g to find them all.
What is catastrophic backtracking?
Nested repeats such as (a+)+ can make the engine try an astronomical number of ways to match before it gives up. On a long enough text it never finishes. The tester stops such a run and tells you, so rewrite the pattern without nested repeats.
Is my text sent anywhere?
No. The pattern and the text stay in your browser, which matters when you test against logs or customer data.
How do I match a dot or a bracket literally?
Put a backslash in front of it: \. matches a dot and \( a bracket. The String Escape tool can escape a whole piece of text for a regular expression.