How to use the regex tester
- Type the pattern without the surrounding slashes, for example \d{3}-\d{4}.
- Add flags: g to find every match, i to ignore case, m for multi-line anchors.
- Paste the text to test and press Test. Each match is listed with its capture groups.
- Or start from one of the common patterns for emails, URLs, US phone numbers and hex colours.
Everything runs in your browser. Nothing you type is sent to our servers. Your last pattern and text are remembered in this browser only.
Regex syntax you will use most
The pattern runs in your browser's JavaScript engine, so the results are exactly what RegExp gives you in JavaScript and Node.js. Other languages are similar but not identical; see the questions below.
| Token | Matches |
|---|---|
| \d \w \s | A digit, a word character (letter, digit or _), whitespace |
| . | Any character except a line break (any at all with the s flag) |
| [abc] [^abc] | One of a, b or c; anything except those |
| * + ? | 0 or more, 1 or more, 0 or 1 of the previous item |
| {3} {2,5} | Exactly 3; between 2 and 5 |
| ^ $ | Start and end of the text (of each line with the m flag) |
| ( ) (?<name> ) | A capture group; a named capture group |
| (?: ) | A group that does not capture |
| (?= ) (?<= ) | Lookahead and lookbehind: check without consuming |
| \b | A word boundary |
Patterns that freeze the page
Some patterns take exponentially longer as the text grows, because the engine tries every way of splitting it. The classic example is a nested quantifier such as (a+)+$ run against a long string of a's followed by one other character. This is called catastrophic backtracking, and it can hang the tab here, or a server in production. Avoid nesting + or * inside another + or *, and make alternatives inside a repeated group unable to match the same text.
When you would use it
- Writing form validation for postcodes, phone numbers or order references.
- Extracting IDs, prices or dates from logs or scraped text.
- Building a search and replace before running it across a codebase.
Frequently asked questions
Why do I only get one match?
Without the g flag a regular expression stops at the first match. Add g to find them all.
Will my pattern work in Python, PHP or Java?
Simple patterns behave the same. Differences show up in named groups (Python uses (?P<name>...)), inline flags, possessive quantifiers and some escapes, so test in the target language before relying on it.
Should I validate email addresses with a regex?
Only loosely. A simple check for something@something.something catches typos. The full email standard is too permissive to match sensibly with a regex, so send a confirmation email to prove the address works.
How do I match a special character such as a dot or bracket?
Escape it with a backslash: \. matches a literal dot and \( a literal bracket. Inside square brackets most characters lose their special meaning.