How to test a regular expression
- Type your pattern between the slashes. Don’t add the slashes yourself.
- Choose flags such as g (find all matches) or i (ignore case).
- Paste the text to search. Matches are highlighted as you type, and the table lists each match with its position and capture groups.
- Optionally enter a replacement to preview the result of a search-and-replace.
This tester uses your browser’s JavaScript regex engine, so results are exactly what String.match, matchAll and replace will do in JavaScript and TypeScript. Most syntax is the same in Python, PHP, Java and C#, but lookbehind, named groups and Unicode classes can differ slightly.
Regex cheat sheet
. | Any character except a line break |
|---|---|
\d \w \s | Digit, word character (letter, digit, _), whitespace |
\D \W \S | Not a digit, not a word character, not whitespace |
[abc] [^abc] [a-z] | One of a, b or c · anything except a, b, c · a range |
* + ? | 0 or more · 1 or more · 0 or 1 |
{3} {2,5} | Exactly 3 · between 2 and 5 |
^ $ \b | Start · end · word boundary |
(…) (?:…) (?<name>…) | Capture group · non-capturing group · named group |
a|b | a or b |
(?=…) (?!…) | Followed by · not followed by |
\p{L} | Any letter in any language (needs the u flag) |
FAQ
Why does the page freeze with some patterns?
Patterns with nested repetition, such as (a+)+$, can take an extremely long time on certain inputs (“catastrophic backtracking”). Make repeated groups more specific to avoid it.