How to use the Regex Tester
- Enter your pattern and choose flags.
- Paste the text to test against.
- Review highlighted matches and the groups table.
- Optionally enter a replacement to preview the result.
Example
| Input | Pattern: \b\w+@\w+\.com\b |
|---|---|
| Result | Matches every “name@site.com” address in the text |
How to test a pattern
Type a regular expression, paste the text you want to search, and the matches are highlighted at once, with a table underneath. It uses your browser’s JavaScript regular expression engine, so what you see is how the pattern behaves in JavaScript and Node.js.
- The match table shows each match, its position (index) and the contents of every capture group.
- The message above the results tells you how many matches were found, or shows the exact error if the pattern is invalid.
- Up to 1,000 matches are searched and the first 200 are listed in the table.
Flags
- g (all matches): find every match, not just the first. On by default.
- i (ignore case): treat uppercase and lowercase as equal.
- m (multiline): make “^” and “$” match at the start and end of each line.
- s (dot matches newline): let “.” match line breaks too.
- u (unicode): turn on full Unicode matching, which is needed for emoji and some scripts.
Common patterns
The “Insert a common pattern” menu fills in a ready-made expression for email addresses, URLs, phone numbers, dates (YYYY-MM-DD), hex colours, IPv4 addresses, numbers, hashtags and capitalized words. Treat them as starting points, because real-world email and phone rules are more complicated.
Find and replace
Type something in “Replace with” to see the replaced text below. Use $1, $2 and so on to insert capture groups, and $& for the whole match. For example, replacing (\w+)@(\w+) with $2 at $1 swaps the two parts of an address.
Tips
- Build the pattern in small pieces and check each one.
- Escape special characters such as . ? * + ( ) [ ] { } with a backslash when you mean them literally.
- If a pattern is slow or never finishes on long text, simplify nested repeats such as (a+)+.
- For plain replacements without patterns, the Find and Replace tool is simpler.
Frequently asked questions
Which regex flavor is used?
JavaScript (ECMAScript) regular expressions, as used in browsers and Node.js. Most syntax is shared with other languages, but features like lookbehind support and named groups can differ.
How do I use capture groups in the replacement?
Use $1, $2 and so on for numbered groups, $<name> for named groups and $& for the whole match.
Does it work for Python, PHP or other languages?
The engine is JavaScript’s. Basic patterns work the same elsewhere, but features such as lookbehind, named groups and flags can differ between languages.
Why does my pattern only find one match?
Make sure the g flag is ticked. Without it the search stops after the first match.