Regex Tester
Test a regular expression against your own text with live highlighting, capture groups and a built-in cheat sheet.
Flags
Highlighted matches
Regex cheat sheet
| Token | Matches |
|---|---|
| . | Any character except newline |
| \d \D | A digit / a non-digit |
| \w \W | Word character (a-z, 0-9, _) / non-word |
| \s \S | Whitespace / non-whitespace |
| ^ $ | Start / end of string (or line with m) |
| \b | Word boundary |
| * + ? | 0 or more / 1 or more / 0 or 1 |
| {n} {n,m} | Exactly n / between n and m times |
| *? +? | Lazy (as few as possible) |
| [abc] [^abc] | Any of a, b, c / none of them |
| [a-z] | Range from a to z |
| a|b | a or b (alternation) |
| ( ) | Capture group |
| (?: ) | Non-capturing group |
| (?<name> ) | Named capture group |
| (?= ) (?! ) | Lookahead / negative lookahead |
| \1 \2 | Backreference to group 1, 2 |
How to read the results
Type a pattern above and the test string below lights up: every match is highlighted, the count appears next to the label, and the table breaks each match down with its position and any capture groups. Everything recomputes as you type, so you can tighten a pattern one character at a time and watch the highlights shift.
A worked example
Say you want every email in a block of text. The pattern
\b[\w.]+@[\w.]+\.\w+\b reads as: a word boundary, one or more word or dot
characters, an at sign, the domain, a dot, and the top-level domain. Add capture groups -
\b([\w.]+)@([\w.]+)\b - and the table will show the local part and the domain
separately for each hit, which is exactly how you would pull them apart in code.
Common gotchas
- Forgetting the g flag - without it you only ever see the first match.
-
Greedy quantifiers -
.*grabs as much as it can. Use.*?when you want the shortest match. -
Unescaped metacharacters - a literal dot or bracket must be written as
\.or\[.
Once your pattern works, put it to use in the find and replace tool, which accepts full regex. For everyday text jobs the word counter and case converter are close at hand too.