Regex Tester

Type a pattern and some text to see every match highlighted, with numbered and named capture groups, plus a live replace preview. Everything runs in your browser.

Flags

Highlighted text

Matches

    Replace preview

    How the tester runs your pattern

    Your pattern is compiled with new RegExp(pattern, flags) — the same engine your JavaScript runs. To list every match the tester iterates with the global flag on internally, even if you leftg unticked; your flags are still what drive thereplace preview, so without g only the first match is substituted. A bad pattern never crashes the page: the engine's error message is shown and the last good highlight stays put. The test text is capped at 100,000 characters and the match list at 10,000 entries.

    Capture groups

    ( … ) captures a numbered group; (?<name> … )captures a named one (it still takes a number too). Use(?: … ) when you only need grouping, not capture. In the replacement string, $1 pastes group 1 and$<name> pastes a named group;$& is the whole match and $$ is a literal dollar.

    Worked example

    Pattern (\w+)@(?<domain>[\w.]+) againstalice@example.com matches the whole address, capturesalice as group 1 and example.com asdomain. Replacement $1 [at] $<domain>rewrites it to alice [at] example.com — a quick way to de-link emails in bulk text.

    Cheat sheet

    TokenMatches
    ^ $start / end of string (or line with m)
    \b \Bword boundary / non-boundary
    .any char except newline (any char with s)
    \d \w \sdigit / word char / whitespace (capitals negate)
    [abc] [^abc] [a-z]character class / negated / range
    * + ?0+, 1+, 0 or 1 — add ? for lazy
    {n} {n,} {n,m}exactly n / n or more / n to m
    (a|b)alternation
    ( ) (?: ) (?<n> )capture / non-capture / named
    (?= ) (?! )lookahead / negative lookahead
    (?<= ) (?<! )lookbehind / negative lookbehind
    \1 \k<n>back-reference to a numbered / named group
    flagsg all, i case, m multiline, s dotall, u unicode, y sticky

    Building a pattern for URLs or slugs? Pair this with theURL encoder, thecase converter or theword counter.

    Related tools

    Frequently asked questions

    Which regex flavour is this?
    JavaScript's, via the built-in RegExp engine. It supports named groups (?...), lookbehind, Unicode property escapes with the u flag and the sticky y flag. It does not support recursion or possessive quantifiers.
    What do the flags do?
    g finds all matches (not just the first), i is case-insensitive, m makes ^ and $ match line boundaries, s lets . match newlines, u enables full Unicode mode, and y (sticky) anchors each match at lastIndex.
    Why is g always effectively on for the match list?
    To list every match the tester iterates with the global flag internally. Your chosen flags are still shown and are used as-is for the replace preview, where a missing g means replace-first-only.
    How do I reference a group in the replacement?
    Use $1, $2 … for numbered groups and $ for named ones. $& is the whole match, $` and $' are the text before and after it, and $$ is a literal dollar sign.
    Is there a size limit?
    Yes — the test text is capped at 100,000 characters and the match list at 10,000 matches, so a runaway pattern can't lock up the page. You'll see a notice when a cap is hit.
    My pattern says 'Invalid regular expression' — why?
    Usually an unbalanced bracket or parenthesis, a stray backslash, or a quantifier with nothing to repeat. The message from the engine names the problem; fix it and the highlight returns.
    Does a zero-width match break anything?
    No. Patterns like (?:) or \b match empty strings between characters; the tester advances past them so it can't loop forever, and they show as empty highlights.
    Is my text uploaded?
    No. The RegExp runs in your browser. Nothing you type is sent anywhere, which matters when the text you're testing against contains real data.

    Last reviewed: September 2026. Figures and formulas are checked against their published sources; see the site's data notes.