Regex Tester

Test JavaScript regular expressions as you type – see every match and group highlighted, replace or split text, understand each part of the pattern and copy working code.

  • Live highlighting
  • Plain-English explanation
  • JS, Python, Java code
  • Safe from runaway patterns

Runs in your browser in a background thread – your text is never uploaded.

Matches and groups

What your pattern means

    Use it in code

    
          

    How to test a regular expression

    1. Write your patternType a regular expression and switch on flags such as g (all matches) or i (ignore case). You can also paste /pattern/flags from code.
    2. Add test textMatches are highlighted as you type, and every match and capture group is listed with its position.
    3. Replace, split or exportSwitch to Replace or Split to see the result, read the plain-English explanation, then copy ready-made JavaScript, Python or Java code.

    Regex cheat sheet

    PatternMatches
    .Any character except a line break
    \d \w \sA digit, a word character, whitespace (capitals mean “not”)
    [abc] [^abc] [a-z]One of a, b or c · anything except those · a range
    * + ? {2,5}0 or more · 1 or more · optional · 2 to 5 times
    *? +?Lazy versions – match as little as possible
    ^ $ \bStart · end · word boundary
    (…) (?:…) (?<name>…)Capture group · non-capturing group · named group
    a|ba or b
    (?=…) (?!…) (?<=…) (?<!…)Followed by · not followed by · preceded by · not preceded by
    \1 \k<name>The same text a group matched earlier

    Tips

    • Prefer specific classes like [^"]* over .* – they’re faster and less surprising.
    • Anchor patterns with ^ and $ (and the m flag) when validating whole lines.
    • Avoid nested quantifiers such as (\w+)*, the usual cause of catastrophic backtracking.

    Frequently asked questions

    Which regex flavour does this tester use?

    Your browser’s JavaScript (ECMAScript) engine – the same one used by Node.js and every web page. Most syntax is shared with Python, Java, PHP and .NET, but a few features differ, such as named group syntax and lookbehind support in some languages.

    What do the flags mean?

    g finds all matches instead of just the first. i ignores upper and lower case. m makes ^ and $ match at the start and end of each line. s lets . match line breaks. u turns on full Unicode support (needed for \p{…}). y matches only at the current position. d records the start and end of each group.

    Why does my pattern freeze other testers?

    Some patterns, like (a+)+$, can take exponential time on certain text – called catastrophic backtracking. This tester runs your regex in a separate background thread and stops it after 1.5 seconds, so the page always stays responsive.

    How do I use capture groups in a replacement?

    Use $1, $2… for numbered groups, $<name> for named groups, $& for the whole match and $$ for a literal dollar sign. For example, pattern (\w+) (\w+) with replacement $2 $1 swaps two words.

    How do I match a literal dot, bracket or other special character?

    Put a backslash before it: \. matches a full stop, \( a bracket and \\ a backslash. Inside square brackets most characters are literal, so [.] also matches a dot.

    Is my text uploaded?

    No. Matching happens in your browser. A share link puts your pattern and text into the link itself (after the #), so it isn’t sent to our server either – but anyone you send it to can read it.

    Does it support lookbehind and named groups?

    Yes. Modern browsers support lookbehind (?<=…), (?<!…) and named groups (?<name>…). The explanation panel describes each one.

    Last updated: