Online Regex Tester

Debug patterns in seconds instead of Stack Overflow threads. This free online regex tester checks your JavaScript regular expression as you type, highlights every match in your test text, counts them, and shows what each capture group grabbed. Invalid patterns get a plain-language error message pointing at the problem — no cryptic console output required. Everything runs locally in your browser.

Test a Regular Expression

Flags
Quick presets

How to Use the Online Regex Tester

Three inputs, instant answers:

  1. Type your pattern into the pattern box — no slashes or delimiters needed, just the raw expression like \d{3}-\d{4}. It is checked the moment you type: a valid pattern shows matches, a broken one shows a plain-language explanation of what went wrong.
  2. Toggle the flags you need. g (find all matches, not just the first) is on by default. Add i for case-insensitive matching, m when ^ and $ should work per line, s when you want . to cross line breaks, u for proper Unicode handling, or y for sticky matching.
  3. Paste your test text and read the results. Every match is highlighted in yellow, the big number tells you how many were found, and the match-details list shows the position of each hit plus exactly what every capture group captured. The Email, URL, and US Phone preset buttons drop in battle-tested patterns so you can experiment immediately.

A handy debugging trick: build patterns incrementally. Start with the simplest version that matches something (\d+ for "some digits"), confirm it highlights, then add one piece at a time — a group here, a quantifier there. When the highlights suddenly vanish, the last piece you added is the culprit. The tester makes this loop nearly instant because every keystroke re-runs the match.

How Regex Matching Works Here

This tester uses your browser's built-in JavaScript regex engine — the exact same RegExp that runs in Node.js, Chrome, and every modern browser — so a pattern that works here works in your JavaScript code verbatim. The pattern compiles with new RegExp(pattern, flags); if compilation throws, you get the error message translated into actionable advice instead of a stack trace.

Matching itself scans left to right through your text. With the g flag, the engine finds every non-overlapping match; without it, you would only ever see the first. Each match records its starting position and the contents of every capture group — the parts of the pattern wrapped in parentheses. In the email pattern ([A-Za-z0-9._%+-]+)@([A-Za-z0-9.-]+\.[A-Za-z]{2,}), group 1 captures the username and group 2 captures the domain, which is exactly what the match-details list shows you.

A few engine behaviors worth knowing: . does not match line breaks unless the s flag is on; ^ and $ anchor to the start and end of the whole text unless m makes them per-line; and quantifiers like * and + are greedy by default, grabbing as much as possible — add a ? after them (.*?) to make them lazy. The u flag switches the engine to Unicode mode, which fixes emoji and astral characters but also makes invalid escapes an error, so only enable it when you need it.

Worked Example

Say you need to pull every email address out of a block of text. Click the Email preset (or type the pattern yourself) and watch it work on the sample text:

StepWhat happensResult
1. Pattern\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\bCompiles cleanly — no error
2. Flagsg (global)Finds all addresses, not just the first
3. Match 1support@example.comFound at position 14
4. Match 2sales@toolnest.ioFound at position 36
5. Match 3jane.doe+filter@mail-server.co.ukFound at position 218 — dots, plus-tags and multi-part domains all match

Three matches, each highlighted in the text. Notice the pattern deliberately rejects things that merely look email-ish: the \b word boundaries and the required @ plus top-level domain keep it honest. If you need the username and domain separately, wrap them in groups — ([A-Za-z0-9._%+-]+)@([A-Za-z0-9.-]+\.[A-Za-z]{2,}) — and the match details will list Group 1 and Group 2 for every hit.

Limitations

This tester implements the JavaScript (ECMAScript) regex flavor. Patterns written for Python, PCRE/PHP, .NET, or Java will mostly work, but flavor-specific features will not: no lookbehind in very old browsers (modern ones support it), no (?P<name>) named-group syntax from Python (JavaScript uses (?<name>)), no atomic groups or possessive quantifiers from PCRE, and no \p{...} Unicode properties without the u flag.

Performance is also real: catastrophic backtracking (nested quantifiers like (a+)+$ on long input) can freeze the tab, because the browser runs the match on the main thread. The tester caps scanning at 1,000 matches as a safety net, but a pathological pattern on a huge text can still hang — keep test inputs modest while experimenting. Finally, regex validates format, not reality: a pattern can confirm that user@example.com looks like an email, but it cannot tell you whether the mailbox exists.

Regular expressions search text; they can't tell you whether the text is valid. For the JSON half of the workflow, our guide to formatting JSON explains validation, pretty-printing and the errors parsers actually report.

Guides for This Tool

Frequently Asked Questions

How do I test a regular expression online?
Type your pattern into the pattern box and paste sample text below it — matches highlight instantly, with a count and capture-group details for every hit. You do not need slashes or delimiters around the pattern, and flags like g (global) and i (case-insensitive) are toggles. Use the Email, URL, or US Phone presets if you want a working example to start from.
What do the regex flags g, i, m, s, u and y do?
g (global) finds all matches instead of stopping at the first; i makes matching case-insensitive; m (multiline) lets ^ and $ match at each line boundary instead of only the start/end of the text; s (dotAll) lets . match line breaks; u enables Unicode mode for correct emoji and astral-character handling; y (sticky) anchors each match attempt to the engine's current position.
Why is my regex invalid, and how do I fix it?
The most common causes are unbalanced parentheses or brackets, a quantifier like * or + with nothing before it, or a special character that needs escaping (for example, a literal dot should be \. and a literal parenthesis should be \(). This tester shows the engine's exact error plus a plain-language hint pointing at the likely culprit — fix that spot and re-test.
What are capture groups in regex?
Anything wrapped in parentheses becomes a capture group, and the engine remembers what that part matched. In ([A-Za-z0-9._%+-]+)@([A-Za-z0-9.-]+\.[A-Za-z]{2,}), group 1 holds the username and group 2 holds the domain. The match-details list in this tester shows each group's contents per match, which is exactly how you would access them in code (match[1], match[2]).
Why does my pattern find no matches?
First check the flags: without i, "Email" will not match "email". Then check your anchors — ^ and $ require the match to span the whole text (or whole line with m). Then look at quantifiers: \d{5} will not match a 4-digit number. Finally, confirm you escaped literal special characters: an unescaped . matches anything, which usually over-matches rather than under-matches, but an unescaped ( breaks the pattern entirely.
Is my test text uploaded to a server?
No. The pattern compiles and runs entirely in your browser using the built-in JavaScript regex engine — your text never leaves your device. You can safely test patterns against private logs, emails, or customer data without worrying about where the data goes.

Related Tools