About the Regex Tester
Write a regular expression and see every match highlighted in your test text as you type, with capture groups, named groups and a live replace preview.
Key features
- Live match highlighting as you type
- Capture groups and named groups for every match
- All JavaScript flags: g, i, m, s, u, y
- Replace preview with $1, $<name> and $&
- Clear error messages for invalid patterns
- Runs locally: your test data never leaves the browser
Build and debug regular expressions
Regular expressions are powerful but easy to get wrong. Type a pattern and some test text to see every match highlighted instantly, along with its position and capture groups. Add a replacement string to preview a search-and-replace.
Quick reference
| Syntax | Meaning |
|---|---|
. | Any character (except new line unless s) |
\d \w \s | Digit, word character, whitespace |
\D \W \S | The opposite of each |
[a-z] [^0-9] | Character set / negated set |
* + ? | 0+, 1+, 0 or 1 |
{3} {2,5} | Exactly 3 / between 2 and 5 |
*? +? | Lazy (as few as possible) |
^ $ | Start / end (of line with m) |
\b | Word boundary |
( ) (?: ) | Capture group / non-capturing group |
(?<name> ) | Named group |
a|b | a or b |
(?= ) (?! ) | Lookahead / negative lookahead |
(?<= ) (?<! ) | Lookbehind / negative lookbehind |
Useful patterns
| Task | Pattern |
|---|---|
| Email (simple) | [\w.+-]+@[\w-]+(\.[\w-]+)+ |
| Date YYYY-MM-DD | \d{4}-\d{2}-\d{2} |
| Hex color | #(?:[0-9a-fA-F]{3}){1,2}\b |
| Whole word "cat" | \bcat\b |
| Trailing spaces | [ \t]+$ (with m) |
| Duplicate words | \b(\w+)\s+\1\b |
| Digits only | ^\d+$ |
Flags
| Flag | Name | Effect |
|---|---|---|
| g | global | Find all matches |
| i | ignore case | a matches A |
| m | multiline | ^ $ match each line |
| s | dotAll | . matches new lines |
| u | unicode | Full Unicode, \p{L} classes |
| y | sticky | Match only at lastIndex |
Related tools
Apply your pattern to a whole document with Find and Replace, or filter lines with Remove Lines Containing.
How to use the Regex Tester
- Type or paste your text into the input box.
- Choose the options you want.
- The result updates instantly as you type.
- Copy the output or download it as a .txt file.