Regex Tester

Test regular expressions online with live matching highlights and capture groups. Type a pattern and a test string to see results instantly, with g/i/m/s/u flags and quick common-pattern chips. Everything runs locally in your browser.

Do not wrap the pattern in slashes. Syntax follows JavaScript RegExp.

Common patterns

How to use

  1. Type your expression in the "Regular expression" box without wrapping slashes, e.g. \d{4}-\d{2}-\d{2} for dates.
  2. Check the flags you need: g finds all matches, i ignores case, m makes ^ and $ match every line, s lets . match newlines, and u enables Unicode mode.
  3. Paste or type a test string below: every match is highlighted in real time, and an invalid pattern is reported instantly.
  4. "Match details" lists the full text of each match and its capture groups in order, so you can verify how your groups are extracted.
  5. For a quick start, click a "Common patterns" chip to fill common expressions such as email, URL, phone number or date into the input.

FAQ

Why do I get "invalid regular expression"?
Usually caused by an unclosed group or a misplaced quantifier, such as ([a-z]+ or a * or + with nothing before it. Make sure brackets are balanced and quantifiers follow a repeatable token; the browser message points near the problem.
What are capture groups used for?
Parts wrapped in parentheses are captured separately: for example (\d{4})-(\d{2}) captures the year and the month. This tool shows each group's value per match, which helps you debug data-extraction rules.
Why is only the first occurrence highlighted without g?
Without the g flag a regular expression matches only the first occurrence by default. Check "g global" to highlight every match in the text.
Is my text uploaded to a server?
No. Matching, highlighting and group inspection are all performed by local browser scripts, so the text you paste never leaves your device.

How to use

  1. Enter the pattern

    Type your expression in the pattern box without wrapping slashes. The syntax is JavaScript RegExp, e.g. \d{4}-\d{2}-\d{2} for a date. Errors are reported the moment the pattern breaks.

  2. Toggle the flags

    Check the flags you need: g finds every match, i ignores case, m makes ^ and $ match per line. s lets the dot cross newlines and u enables full Unicode mode.

  3. Paste the test string

    Paste or type the text to test into the textarea. Every match is highlighted live, and an invalid pattern shows a status message instead of silently failing.

  4. Inspect the match details

    Open the Match details list to read each match in full, with its capture groups in order. This is the quickest way to confirm parentheses extract what you planned.

  5. Start from common patterns

    Click a chip under Common patterns to load a proven expression. The chips cover email, URL, phone, IP address and date. Then adjust the pattern to your own data format.

About this tool

This is a live regular-expression workbench that runs entirely in the browser. Type a pattern and flags plus a test string, and every match is highlighted immediately. Each capture group is listed under Match details, so you can see exactly what a rule extracts before it touches production code. Invalid patterns are caught instantly with the browser's own diagnostic, replacing the write-run-guess loop inside an editor.

Reach for it before committing a data-extraction rule, or when a validation regex fails to reject input it should. It also helps while you learn how quantifiers, anchors and groups behave. It suits frontend and backend developers, QA engineers testing rules against real samples, and analysts pulling structured values out of messy log lines. Anyone who would otherwise debug regex by scattering console.log statements through their code can use it too.

How it works

Regular expressions trace back to Stephen Kleene's regular-set theory of 1951, and Ken Thompson brought them into the QED and ed editors. Implementations split into two camps. DFA engines built on Thompson's construction scan in steady linear time but cannot support backreferences. JavaScript uses a backtracking NFA engine, which is more flexible and pays for it. Nested quantifiers such as (a+)+ can force exponential backtracking on a failed match. One line of regex can freeze a page for minutes; that is the notorious catastrophic backtracking.

JavaScript adds an escaping double standard. A string literal consumes one layer of backslashes first. So the \d that works in a regex literal must be written \\d inside the RegExp constructor. Patterns copied out of string constants fail in exactly this way. Two state details also bite. The g flag makes a RegExp object carry lastIndex, so reusing one object across calls skips matches. Quantifiers are greedy by default; appending a question mark makes them lazy and shortest-first, which changes what quoted-content extraction captures.

When to use it

  1. Designing extraction rules

    Before writing a scraper or log parser, drop the candidate pattern in with several real samples. Inspect each capture group's output for stray text. Edge cases surface immediately, which beats patching the rule after it has shipped.

  2. Debugging validation that passes bad input

    When input that should be rejected slips through, reproduce it here with the validation pattern. Usual suspects are missing ^ and $ anchors, a forgotten i flag, or an excluded symbol absent from the character class.

  3. Auditing third-party regex safety

    When inheriting legacy code or a validation library, test any suspicious expression against one long non-matching string. A highlight that never appears, or a stalled page, signals runaway backtracking. The fix is rewriting the pattern, not adding server capacity.

Tips & tricks

  • Without the g flag only the first occurrence is highlighted. Tick g global whenever you need every match in the text, not just the opening one.
  • An invalid-regex message usually means an unclosed group or a quantifier with nothing to repeat. ([a-z]+ is missing its closing bracket, for example. Check bracket balance first, then the placement of * and +.
  • Parentheses capture separately: (\d{4})-(\d{2}) splits a date into year and month. Verify group output here before wiring the rule into your extraction code.

Things to watch

  • Nested quantifiers cause exponential backtracking

    Patterns like (a+)+ or (\w+)* backtrack exponentially when text matches a lot and then fails, and the browser can freeze. Keep one long non-matching sample ready and test against it before such a pattern ships.

  • Validation patterns without anchors

    Without ^ and $ a pattern extracts matches from anywhere in longer text. A phone-number check then accepts eleven consecutive digits inside an order number. Anchor validation patterns at both ends, or constrain them with \b word boundaries.

  • Invisible characters break matches

    Full-width spaces and non-breaking spaces (\u00A0) hiding in test text make correct-looking patterns fail. Matching with \s instead of a literal space covers these characters too. If it still fails, clean the text source first.

Related Tools