Regex Tester

Write a regular expression and see what it matches while you type — with groups, replacement preview, a plain-language explanation of every token and ready-to-use code.

  • Live matching
  • Explains the pattern
  • Code for 7 languages
  • Runs locally
Function

Use $1, $2 … for groups, $<name> for named groups and $& for the whole match.

Matches

No match

Pattern explained

    Enter a pattern to see what each part does.

    Common patterns

    Click a pattern to load it together with a sample text. Adjust it to your rules — real-world data is messier than any example.

    Use it in your code

    The snippet translates flags and group syntax. Engines differ in details — Go, for example, has no lookaround or backreferences — so test in the target language too.

    Quick reference
    .Any character except a line break
    \dA digit (0–9)
    \wA word character (letter, digit or _)
    \sA whitespace character (space, tab, line break)
    \D \W \SThe opposite: not a digit, word character, whitespace
    [abc]One of the characters a, b or c
    [^abc]Any character except a, b or c
    [a-z]A character in the range a to z
    ^Start of the text
    $End of the text
    \bA word boundary
    a|bOr — either the part before or the part after
    (…)Capturing group
    (?:…)Group without capturing
    (?<name>…)Named capturing group
    \1The same text as group 1 matched
    (?=…)Lookahead — must be followed by …
    (?!…)Negative lookahead — must not be followed by …
    (?<=…)Lookbehind — must be preceded by …
    (?<!…)Negative lookbehind — must not be preceded by …
    *Zero or more times
    +One or more times
    ?Optional (zero or one time)
    {3}Exactly 3 times
    {2,5}Between 2 and 5 times
    *? +?Lazy: as few as possible
    \.A literal dot (escaped special character)
    \p{L}Any letter of any language (needs the u flag)
    How it works

    How to test a regular expression

    Pattern on top, text below.

    1. 1

      Enter your pattern

      Type it without the surrounding slashes and switch the flags you need on or off.

    2. 2

      Add test text

      Paste real examples — lines that should match and lines that should not. Matches are highlighted immediately.

    3. 3

      Inspect, replace, export

      Check each match and its groups, try a replacement, then copy the code snippet for your language.

    Why ToolCMB

    See what the pattern really does

    Fewer surprises in production.

    Highlighting in place

    Matches are marked directly in your text; click one in the list to jump to it.

    Groups laid out

    Every match shows its numbered and named capture groups, including groups that did not take part.

    Replace and split

    Preview a replacement with $1, $<name> and $&, or see the pieces a split produces.

    Explained in plain words

    Each token of the pattern is described — quantifiers, classes, groups, lookarounds — so you can read someone else’s regex.

    Copy as code

    Get the pattern with the right escaping and flags for JavaScript, Python, PHP, Java, C#, Go or Ruby.

    Protected against runaway patterns

    Matching runs in a background thread. A pattern that backtracks catastrophically is stopped after a moment instead of freezing the page.

    Shareable link

    Copy a link that opens the tool with the same content. The data sits in the part of the address after #, which browsers do not send to servers.

    Private by design

    Everything runs in your browser. What you type or open is not sent to a server.

    Regular expressions in five minutes

    A regular expression describes a pattern of characters. Most characters stand for themselves; a few have special meaning. Character classes such as \d (a digit), \w (a word character) or [a-f] match one character from a set. Quantifiers say how often: * zero or more, + one or more, ? optional, {2,4} two to four times. Anchors like ^, $ and \b match positions, not characters.

    Parentheses create groups. A capturing group remembers what it matched, so you can reuse it in a replacement ($1) or read it in code; (?<year>\d{4}) gives the group a name. Quantifiers are greedy by default — they take as much as possible — and become lazy with a trailing ?. That difference explains most “it matches too much” problems, for example <.+> against <.+?>.

    This tester uses your browser’s JavaScript engine, so results are exact for JavaScript and TypeScript and very close for other languages. The main differences elsewhere: Python writes named groups as (?P<name>…), Go’s RE2 engine has no lookarounds or backreferences, and flags are passed differently. Always validate security-relevant input — e-mail addresses, URLs — with a dedicated parser rather than with a regex alone.

    The flags

    FlagNameEffect
    gglobalFind every match instead of stopping after the first
    iignore caseUpper and lower case letters are treated as equal
    mmultiline^ and $ also match at the start and end of each line
    sdot allThe dot also matches line breaks
    uunicodeTreats the text as Unicode code points and enables \p{…}
    ystickyMatches only at the exact position where the last match ended

    Tips

    • Format the code around your pattern with the Code Formatter.
    • Matching inside JSON? Make the structure readable first with the JSON Formatter.
    • Decode percent-encoded text before matching it with the URL Encoder-Decoder.
    • Avoid nested quantifiers such as (a+)+ or (.*)* on user input: they can take exponential time (ReDoS). Make the inner part unambiguous instead.
    FAQ

    Frequently asked questions

    Can’t find your answer? Contact us — we reply quickly.

    Which regex flavor does this tester use?

    The JavaScript (ECMAScript) engine built into your browser, including lookbehind, named groups and Unicode property escapes. Patterns behave identically in JavaScript, TypeScript and Node.js.

    Why does my pattern only find the first match?

    Without the g (global) flag, a regular expression stops after the first match. Switch on g to find all of them.

    What is the difference between greedy and lazy?

    A greedy quantifier (.*) matches as much as possible and then gives back characters if needed; a lazy one (.*?) matches as little as possible. Lazy quantifiers are what you want between two delimiters.

    What does “catastrophic backtracking” mean?

    Some patterns can try an exponential number of ways to match a text, typically with nested quantifiers such as (a+)+$. The tester stops such a run after about two seconds and tells you.

    Can I use the pattern in Python or PHP?

    Usually yes. The code section converts flags, escaping and named-group syntax for Python, PHP, Java, C#, Go and Ruby. Test the result in the target language, because the engines differ in details.

    Is my data sent to a server?

    No. The tool runs entirely in your browser. Your input is not uploaded, logged or stored on our servers.

    More free developer tools

    Encode, format, test, convert and generate — small tools that run in your browser and keep your data on your device.

    Browse all tools