How do I test a regular expression?
Run the pattern against sample text that includes cases it should match and cases it should not, then check each match and capture group. Type both here and the matches update as you type.
- Type the pattern without the surrounding slashes.
- Tick flags: g for all matches, i to ignore case, m for line anchors, s so dot matches newlines.
- Paste test text with good and bad examples.
- Check highlights and the groups table.
- Try a replacement using $1, $2 for groups.
Examples
Pull the domain from emails
Input
Pattern: (\w+)@([\w.-]+\.\w+) Text: Contact jane@acme.com
Result
Match: jane@acme.com Group 1: jane Group 2: acme.com
Reformat dates
Input
Pattern: (\d{4})-(\d{2})-(\d{2})
Replace: $2/$3/$1
Text: 2026-11-09Result
11/09/2026
Frequently asked questions
Which regex flavor is this?
JavaScript (ECMAScript), as run by your browser. Most syntax is shared with Python, PHP and Java, but lookbehind support and named group syntax can differ.
Why does my pattern only find one match?
Turn on the g flag. Without it, a regex stops after the first match.
How do I match a literal dot or bracket?
Escape it with a backslash, like \. or \[.
Can a bad regex freeze the page?
Some patterns with nested repeats take a very long time on certain text. The tool stops after 5,000 matches, but rewrite patterns like (a+)+ if the page slows down.