Developer tool
Regex tester
Write a regular expression and see what it matches as you type. Uses JavaScript's regex engine, the same one as your browser and Node.js.
Advertisement
//
Matches highlighted
Matches
Replace
Use $1, $2 for groups, $<name> for named groups, and $& for the whole match.
Advertisement
Regex cheat sheet
| Pattern | Matches |
|---|---|
| . | Any character except a new line |
| \d \w \s | A digit, a word character (letter, digit, _), a space or tab |
| \D \W \S | The opposite of the above |
| [abc] [^abc] [a-z] | One of a, b or c · anything except them · a to z |
| * + ? {3} {2,5} | 0 or more · 1 or more · optional · exactly 3 · 2 to 5 times |
| *? +? | As few as possible (lazy) |
| ^ $ \b | Start · end · a word boundary |
| (abc) (?:abc) (?<name>abc) | Capture group · group without capturing · named group |
| a|b | a or b |
| (?=x) (?!x) (?<=x) (?<!x) | Followed by x · not followed by x · after x · not after x |
| \. \* \( \\ | A real dot, star, bracket or backslash |
Useful patterns
- Indian mobile number:
^[6-9]\d{9}$ - PIN code:
^[1-9]\d{5}$ - PAN:
^[A-Z]{5}\d{4}[A-Z]$ - Date dd/mm/yyyy:
^(0[1-9]|[12]\d|3[01])/(0[1-9]|1[0-2])/\d{4}$
The page froze on my pattern.
Some patterns, like (a+)+$, can take an extremely long time on certain text ("catastrophic backtracking"). Reload the page and rewrite the pattern without nested repeats.
Advertisement