Regex Tester

Write a regular expression and see every match highlighted in your test text as you type, with capture groups, named groups, a replace preview and a plain-English explanation of each part of the pattern. Uses the JavaScript regex engine and runs entirely in your browser.

g global, i ignore case, m multiline, s dot-all, u unicode, y sticky
Pattern and test text
Matches


                            
#IndexMatchGroups

Replace result

What the pattern means

    How to test a regular expression

    1. Type your patternWrite it without the surrounding slashes, for example \d{3}-\d{4}. Pick a common pattern from the list to start from a working example.
    2. Set the flagsUse g to find every match rather than just the first, i to ignore case and m so ^ and $ match at each line.
    3. Paste test textMatches are highlighted as you type, and the table lists each match with its position and capture groups.
    4. Try a replacementEnter replacement text to preview the result of String.replace, including $1 and named group references.

    Regex syntax cheat sheet

    TokenMeaning
    .Any character except a line break (any character with the s flag)
    \d \w \sA digit, a word character (letter, digit or underscore), a whitespace character. Capitals (\D \W \S) mean the opposite.
    [abc] [^abc] [a-z]One of a, b or c; anything except a, b or c; any lowercase letter
    ^ $ \bStart of text (or line), end of text (or line), a word boundary
    * + ? {n} {n,m}Zero or more, one or more, optional, exactly n, between n and m times
    *? +?Lazy versions that match as little as possible
    ( ) (?: ) (?<name> )Capturing group, non-capturing group, named group
    a|bEither a or b
    (?= ) (?! ) (?<= ) (?<! )Lookahead, negative lookahead, lookbehind, negative lookbehind

    Which regex flavour does this use?

    This tester uses your browser's built-in JavaScript (ECMAScript) engine, so results match exactly what RegExp, String.match, matchAll and replace do in Node.js and in the browser. Most everyday syntax is shared with Python, Java, PHP (PCRE) and Go, but a few features differ: possessive quantifiers and atomic groups are not available in JavaScript, and Go's RE2 does not support lookarounds or backreferences. Test in the language you will deploy to when you rely on advanced features.

    Protection against slow patterns

    Some patterns, such as ^(a+)+$, take exponentially longer as the input grows. This is called catastrophic backtracking and can freeze a page or, on a server, cause a denial of service (ReDoS). The tester runs each pattern in a background worker and stops it after two seconds, so a slow pattern shows a warning instead of locking up your browser. If you see the warning, remove nested quantifiers or make the alternatives more specific.

    Frequently asked questions

    Why does my pattern only find one match?

    Add the g (global) flag. Without it, JavaScript stops after the first match.

    Do I need to escape slashes?

    No. You type the pattern without the surrounding slashes, so a forward slash is just a normal character here. In JavaScript source code inside /…/ you would write \/.

    How do I match a literal dot or bracket?

    Put a backslash in front of it: \. matches a dot, \( a bracket and \\ a backslash.

    What do $1 and $<name> mean in the replacement?

    $1 inserts the text of the first capture group, $<name> the named group called name, and $& the whole match.

    Is my text sent anywhere?

    No. Matching happens in your browser. Nothing is uploaded or stored.

    Related tools