Regex Tester

Test JavaScript regular expressions with live match highlighting, capture groups and named groups. Includes common patterns and a quick syntax reference.

Try:

    How to use the regex tester

    Type a pattern in the Pattern box and some sample text below it. Matches are highlighted as you type, and the list underneath shows every match with its position and any capture groups. The tester uses your browser's JavaScript engine, so what you see here is exactly what String.prototype.match, replace or matchAll will do in Node.js or the browser.

    Don't add the surrounding slashes. Write \d+, not /\d+/g. Flags go in the separate box.

    The flags, briefly

    FlagWhat it does
    gGlobal: find all matches instead of stopping at the first one.
    iCase-insensitive.
    mMultiline: ^ and $ match at the start and end of every line, not just the whole string.
    sDot-all: . also matches newline characters.
    uUnicode mode. Needed for \p{L}-style property escapes and correct handling of emoji.
    ySticky: only match at the exact current position. Rarely needed outside of tokenizers.

    A tiny cheat sheet

    • \d digit, \w letter/digit/underscore, \s whitespace. Capitals negate them: \D, \W, \S.
    • * zero or more, + one or more, ? optional, {2,5} between two and five.
    • Add ? after a quantifier to make it lazy: .+? matches as little as possible.
    • ( ) captures, (?: ) groups without capturing, (?<name> ) creates a named group.
    • \b is a word boundary. \bcat\b matches "cat" but not "concatenate".
    • Lookahead (?= ) and lookbehind (?<= ) check context without consuming it.

    If this is all a bit hazy, our practical regex primer explains each of these with real examples.

    Common mistakes

    The most frequent one is forgetting to escape a dot. example.com also matches "exampleXcom" because an unescaped dot means "any character". Write example\.com. The second is greedy matching: <.+> on an HTML line matches from the first < to the very last >. Use <.+?> or, better, <[^>]+>.

    Finally, be careful with patterns like (a+)+ run against long input. Nested quantifiers can cause "catastrophic backtracking", where the engine tries an exponential number of combinations and appears to freeze.

    Frequently asked questions

    Which regex flavour does this use?

    JavaScript (ECMAScript). It runs on the same engine as your browser, so behaviour matches Node.js and front-end code. PCRE features like possessive quantifiers or recursion are not available.

    Why do I only see one match?

    Without the g flag a JavaScript regex stops after the first match. Add g in the flags box to find them all.

    How do I match a literal special character?

    Put a backslash in front of it. The characters that need escaping are . * + ? ^ $ { } ( ) | [ ] \ and /.

    Is my test text sent anywhere?

    No. Matching happens entirely in your browser.