Regex Tester

Test regular expressions with live matches and a plain-English explanation.

Free tools that run in your browser. Nothing you type, open or create is uploaded to NerdBible or anyone else.

Flags

Matches appear here as you type.

What this pattern means
    Matches highlighted
    
      
    Result after replacing
    
      
    Cheat sheet
    .Any character except a line break (with the s flag, line breaks too)
    \d \w \sA digit, a word character (letter, digit, _), a space or other white space
    \D \W \SThe opposite: not a digit, not a word character, not white space
    [abc] [^abc] [a-z]One of the listed characters, none of them, or a range
    ^ $Start and end of the text (of each line with the m flag)
    \bA word boundary
    * + ?Zero or more, one or more, zero or one of the previous item
    {3} {2,5} {2,}Exactly 3, between 2 and 5, 2 or more
    *? +?Lazy: match as few as possible
    (abc) (?:abc)A capturing group, a group that does not capture
    (?<name>abc)A named group, used as $<name> in the replacement
    a|ba or b
    (?=x) (?!x)Followed by x, not followed by x
    (?<=x) (?<!x)Preceded by x, not preceded by x
    \1 \k<name>The same text a group matched earlier
    $& $1 $<name>In the replacement: the whole match, group 1, a named group

    This uses your browser's JavaScript regular expression engine, so the results match what JavaScript code will do. Other languages (PCRE in PHP, Python's re) agree on most patterns but differ on some details. Matching runs in a background worker that is stopped after 1.5 seconds, so a pattern that backtracks endlessly cannot freeze the page, and at most 1,000 matches are listed.

    How to use it

    1. Type a pattern without the surrounding slashes and tick the flags you need. Under the result, What this pattern means breaks it down piece by piece in plain English.
    2. Paste the text to test. Matches are highlighted as you type, with every group listed in the table.
    3. Try a replacement using $1 or $<name> and copy the result.

    Questions

    Why does my pattern only find the first match?

    Without the g flag, a JavaScript regular expression stops at the first match. Tick g to find them all.

    What is catastrophic backtracking?

    Nested repeats such as (a+)+ can make the engine try an astronomical number of ways to match before it gives up. On a long enough text it never finishes. The tester stops such a run and tells you, so rewrite the pattern without nested repeats.

    How does the plain-English explanation work?

    The pattern is split into its parts as you type: groups, character classes, escapes such as \d, anchors, lookarounds, alternatives and quantifiers. Each part is listed with what it matches, nested under the group it sits in, followed by what each ticked flag does. It describes JavaScript regular expression syntax.

    Is my text sent anywhere?

    No. The pattern and the text stay in your browser, which matters when you test against logs or customer data.

    How do I match a dot or a bracket literally?

    Put a backslash in front of it: \. matches a dot and \( a bracket. The String Escape tool can escape a whole piece of text for a regular expression.

    About this tool

    About the regex tester

    Regular expressions are compact and powerful and very easy to get slightly wrong. Type a pattern, paste some text and every match is highlighted as you type, with each capture group listed in a table underneath.

    Features

    • Flags such as g (all matches), i (ignore case), m (multiline), s (dot matches line breaks) and u (Unicode).
    • Named and numbered groups shown for every match.
    • A replacement box using $1 or $<name>, with the result ready to copy.
    • A quick reference to the common tokens.

    The pattern in plain English

    Under the result, the pattern is broken into its parts as you type: each group, character class, escape such as \d, anchor, lookahead or lookbehind, alternative and quantifier is listed with what it matches, nested under the group it belongs to, followed by what each ticked flag does. It is a quick way to read a pattern someone else wrote, or to check that yours says what you meant.

    Which engine?

    Matching uses your browser's JavaScript regular expression engine, so results are exactly what JavaScript code will do. PCRE in PHP and Python's re agree on most patterns but differ in some details, such as lookbehind support and certain escapes.

    Protected from catastrophic backtracking

    Nested repeats such as (a+)+ can make an engine try an astronomical number of combinations. Here matching runs in a background worker that is stopped after 1.5 seconds, so a runaway pattern cannot freeze the page; you are told, and can rewrite it. At most 1,000 matches are listed.

    Common slip

    Without the g flag, JavaScript stops at the first match. Tick it to find them all.

    Your pattern and text stay in your browser, which matters when testing against logs or customer data.

    Related tools