Regex Tester
Runs in your browserTest a regular expression against sample text with live match highlighting.
Pattern
//g
Test string
What is a Regex Tester?
A regular expression is a pattern for matching text — a compact way to say "a digit, then three letters, then any number of spaces" instead of writing that out as code. JavaScript's regex engine, like most modern ones, supports literal characters, character classes, quantifiers, groups, and lookaheads, all combined into one pattern.
Testing a pattern against real sample text — rather than just reading it — is the fastest way to catch the two most common mistakes: a quantifier that is greedier than intended, and a character class that is narrower or wider than you meant. Seeing exactly which parts of your text highlight green makes both obvious immediately.
How to use it
- Type your pattern into the Pattern field, without the surrounding slashes.
- Toggle flags: g for all matches (added automatically for this tool so you can see every match at once), i for case-insensitive, m for multiline anchors, s for dot to match newlines.
- Paste your sample text into the Test string panel. Matches highlight as you type.
- Open the Matches panel to see each match's position, full text, and any capture groups — named and numbered.
Example
Matching an email address
Pattern: \b[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}\b
Text: Contact ada@example.com or grace@navy.milMatches: ada@example.com, grace@navy.milFrequently asked questions
Why does my pattern match more than I expected?
Almost always a greedy quantifier. `.*` grabs as much as possible and only backs off if the rest of the pattern fails to match, so `".*"` against `"a" and "b"` matches the whole `"a" and "b"` rather than stopping at the first closing quote. Use the lazy version, `.*?`, to match as little as possible instead.
Why is my pattern invalid?
Usually an unescaped special character, an unbalanced parenthesis or bracket, or a quantifier with nothing before it to repeat. This tool surfaces the JavaScript engine's own error message, which names what it expected.
Does this test with the global flag even if I don't select it?
For finding and highlighting matches, yes — a copy of your pattern with `g` added is used internally so every match in the text is shown, since that is what a tester is for. Your selected flags otherwise apply exactly as chosen, including case sensitivity and multiline behaviour.
What is a capture group?
Parentheses in a pattern, `(...)`, capture the text they matched so you can reference it separately from the overall match — useful for extracting just the domain from an email, for instance. Named groups, written `(?<name>...)`, let you label that captured piece instead of referring to it by position.
Is it safe to test a slow or complex pattern here?
Yes for your own use — everything runs in your own browser tab, so a pathological pattern only ever affects your own session, never a server or other users. If a pattern seems to hang, refresh the tab.