What it does
The Regex Tester runs a regular expression against your text as you type. Matches are highlighted, each match is listed with its capture groups (including named groups), and a replace box shows the result of a search-and-replace. It uses JavaScript's regular expression engine.
How to use it
- Type the pattern without slashes.
- Tick the flags you need: g global, i ignore case, m multiline, s dotAll, u unicode, y sticky.
- Paste the Test string, or open a file.
- Check the highlighted matches and the groups.
- Type a replacement under Replace with, using
$1orfor groups.lt;name>
Example
Pattern:
(?<user>[\w.]+)@(?<domain>[\w.-]+)
Text: Contact ada@example.com or linus@kernel.org
| Match | user | domain |
|---|---|---|
| ada@example.com | ada | example.com |
| linus@kernel.org | linus | kernel.org |
Replacing with gives Contact ada at example.com or linus at kernel.org.
Good to know
- JavaScript regex supports lookbehind, named groups and Unicode property escapes such as
\p{L}, but not possessive quantifiers or recursion. Patterns from PCRE (PHP), Python or .NET usually work with small changes. - Without the g flag only the first match is found.
- m makes
^and$match at every line; s lets.match newlines.
FAQ
Why is my pattern so slow?
Nested quantifiers such as (a+)+ can take exponential time on some inputs. Make the pattern more specific.
How do I match a literal dot or bracket?
Escape it with a backslash: \., \( or \[.