Regex Tester

Write a regular expression and see every match highlighted live in your test text. Inspect capture groups and named groups in a table, toggle flags (g, i, m, s, u, y), preview search-and-replace with $1 backreferences, and read a plain-English explanation of each part of your pattern. Start from a library of common patterns for emails, URLs, dates, IP addresses and more. Patterns run safely in a background worker, so a runaway regex can't freeze your browser.

  • 100% free
  • No sign-up
  • Private & local
  • Works on mobile
//

Matches & groups

Replace

Pattern explained

    JavaScript code

    Private by design: every calculation runs locally in your browser. Nothing you type is sent to a server or stored by us.

    What Is a Regex Tester?

    A regular expression (regex or regexp) is a compact pattern that describes text: "an @ sign between two groups of letters", "four digits, a dash, two digits", "a word repeated twice". Regexes are used everywhere in software for validating form input, searching and replacing in editors, parsing log files, extracting data, routing URLs and cleaning up text. They're powerful but notoriously easy to get wrong, which is why a regex tester that shows matches live is invaluable.

    This tester uses your browser's own JavaScript regex engine, so the results are exactly what you'll get in JavaScript, TypeScript and Node.js, and are very close to most other languages for common patterns.

    How to Use the Regex Tester

    1. Type your pattern between the slashes, or pick one from the library.
    2. Choose flags: g finds all matches, i ignores case, m makes ^ and $ match at line breaks, s lets . match newlines, u enables full Unicode, and y is sticky.
    3. Paste your test text. Matches are highlighted instantly, in alternating colours so adjacent matches are easy to see.
    4. Inspect the table for each match's position and its capture and named groups.
    5. Try a replacement using $1, $<name> or $& (the whole match).
    6. Read the explanation to check each token does what you intended, then copy the ready-made JavaScript code.

    Regex Cheat Sheet

    TokenMeaningTokenMeaning
    .Any character\d \w \sDigit, word char, whitespace
    *0 or more\D \W \STheir opposites
    +1 or more[abc]One of a, b or c
    ?Optional, or lazy after a quantifier[^abc]Anything except a, b, c
    {2,5}2 to 5 times^ $Start / end
    (…)Capturing group\bWord boundary
    (?:…)Non-capturing groupa|ba or b
    (?<name>…)Named group(?=…) (?!…)Lookahead / negative

    Catastrophic Backtracking

    Some patterns, especially nested quantifiers like (a+)+$ or (\w+\s?)*$, can take exponential time on inputs that almost match, freezing a browser tab or even taking down a server (a "ReDoS" attack). This tester runs every pattern in a separate Web Worker and stops it after 1.5 seconds, telling you what went wrong instead of hanging. To fix a slow pattern, remove nested quantifiers, make character classes more specific, and anchor patterns where possible.

    Regex in Other Languages

    Most syntax here, including classes, quantifiers, groups, anchors and lookahead, works the same in Python, Java, C#, PHP (PCRE), Ruby and Go. Differences to watch: Python uses (?P<name>…) for named groups; Go's RE2 has no lookarounds or backreferences; lookbehind support varies; and in many languages you must double every backslash inside string literals.

    Tips for Writing Better Regular Expressions

    • Start simple and build up, testing against both text that should match and text that shouldn't.
    • Anchor your patterns with ^ and $ when validating whole inputs; otherwise "abc123" matches \d+.
    • Prefer specific classes: [^"]* is faster and safer than .* inside quotes.
    • Use named groups to make patterns and replacements self-documenting.
    • Use non-capturing groups (?:…) when you only need grouping, not capturing.
    • Comment complex patterns in your code, or split them into smaller named pieces.

    Useful Everyday Patterns

    • Trim spaces at line ends: [ \t]+$ with the m flag, replaced with nothing.
    • Collapse multiple spaces: {2,} replaced with a single space.
    • Find blank lines: ^\s*$ with the m flag.
    • Swap "Last, First" to "First Last": (\w+),\s*(\w+) replaced with $2 $1.
    • Extract hashtags: #\w+ with the g flag.
    • Match a whole word only: wrap it in \b, e.g. \bcat\b, which won't match "category".

    Try each pattern above in the tester with your own text to see exactly what it matches before using it in code or in your editor's find-and-replace.

    Frequently Asked Questions

    Why does my regex only find one match?

    Turn on the g (global) flag to find all matches.

    How do I match a literal dot or bracket?

    Escape it with a backslash: \. \( \[. The String Escaper tool can escape any text for regex.

    What's the difference between greedy and lazy?

    Greedy quantifiers (*, +) match as much as possible. Adding ? (*?, +?) makes them match as little as possible.

    Is there a perfect email regex?

    No. Use a simple pattern for basic validation and confirm addresses by sending an email.

    Is my text sent anywhere?

    No. Everything runs in your browser.