Regex Tester

Write a JavaScript regular expression, choose its flags and paste some text to see every match highlighted, with positions and capture groups. Turn on the replacement preview to see the result of a find-and-replace. Everything runs in your browser; your pattern and text are never uploaded, and a safety timeout stops patterns that would freeze the page.

Processed locally in your browser. Your data is not uploaded to our servers.

Write the pattern without the surrounding slashes. It uses JavaScript syntax.

Flags

Your pattern and text stay in this page: they are never uploaded or sent to analytics.

SettingsDefault settings

Result

    Examples

    Load one of these ready-made patterns and edit it:

    GoalPattern
    Dates (year, month, day) with a day/month/year replacement/(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/g
    Email addresses/[\w.+-]+@[\w-]+\.[\w.-]+/g
    Numbers, with optional decimals/-?\d+(?:\.\d+)?/g
    Hexadecimal colours/#(?:[0-9a-f]{3}){1,2}\b/gi
    Words in any language (Unicode)/\p{L}+/gu
    Repeated words, replaced by one/\b(\w+)\s+\1\b/gi

    Formula & Methodology

    Your pattern is compiled by your browser’s own JavaScript RegExp engine and run against the text. The page then lists every match with its position and capture groups. The replacement preview expands $1, $<name>, $& and the other special sequences exactly as String.replace does. Nothing you type is executed as code.

    Flags

    g Global (all matches)Find all matches instead of only the first.
    i Ignore caseLetters match in upper and lower case.
    m Multiline^ and $ match at the start and end of every line.
    s Dot matches newlineThe dot also matches line breaks.
    u Unicode modeFull Unicode support: code points, \p{…} properties and stricter escapes.
    v Unicode sets modeAn upgraded Unicode mode with set operations in classes. Cannot be combined with u.
    y StickyMatch only at the exact position where the search starts.

    Quick reference

    SyntaxMeaning
    .Any character except a line break (with the s flag, any character).
    \d \w \sA digit, a word character (letter, digit, underscore) or a whitespace character.
    \D \W \SThe opposite of each: not a digit, not a word character, not whitespace.
    ^ $The start and the end of the text (or of each line with the m flag).
    \b \BA word boundary, or a position that is not a word boundary.
    [abc] [^abc] [a-z]One character from a set, from outside a set, or from a range.
    (…)A capture group, numbered from 1 by the position of its opening parenthesis.
    (?<name>…) \k<name>A named capture group and a reference to it.
    (?:…)A group that groups without capturing.
    a|bEither the expression before or the one after the bar.
    * + ? {n,m}Zero or more, one or more, zero or one, or between n and m repetitions.
    *? +? ??The same repetitions, but matching as little as possible (lazy).
    (?=…) (?!…)Lookahead: what follows must (or must not) match, without being part of the match.
    (?<=…) (?<!…)Lookbehind: what precedes must (or must not) match, without being part of the match.
    \p{L} \p{Script=Arabic}Unicode properties: any letter, or any letter in a given script (needs the u or v flag).

    Replacement text

    $1 … $99The text of capture group 1 to 99.
    $<name>The text of a named capture group.
    $&The whole matched text.
    $`The text before the match.
    $'The text after the match.
    $$A literal dollar sign.

    Notes and limitations

    • This is the JavaScript regular-expression flavour. Features of other languages, such as possessive quantifiers, atomic groups, inline flags or recursion, may not work or may mean something different.
    • Results come from your browser’s RegExp engine, so very new syntax depends on your browser version.
    • A test that takes longer than 2 seconds is stopped to protect the page. Patterns with nested quantifiers can take exponential time on some texts.
    • Up to 10,000 matches are listed, in texts of up to 1,000,000 characters and patterns of up to 10,000 characters.
    • The d (indices) flag is used internally to report group positions and is not offered as an option. Positions count UTF-16 code units, like JavaScript string indexes.

    How to Use

    1. Type your regular expression in the first box, without slashes.
    2. Tick the flags you need. For example g finds every match and i ignores letter case.
    3. Paste or type the text to search. Matches are highlighted as you type.
    4. Read the match list for positions and capture groups. If the expression is invalid, the message says why.
    5. Optionally turn on the replacement preview, then copy the pattern or the replaced text.

    Frequently Asked Questions

    Which regular-expression flavour does this use?

    JavaScript’s. The pattern runs on your browser’s built-in RegExp engine, so it behaves exactly as it would in JavaScript code in that browser. Other languages such as Python, PHP, Java or .NET have small differences.

    Is my text uploaded or is my pattern run on a server?

    No. Matching happens in your browser, in a background worker. The pattern and text are not sent to ToolQuarter, analytics or any other service. Pasted text is never executed as code.

    Why was my test stopped after 2 seconds?

    Some patterns, especially those with nested repetition such as (a+)+, can take an enormous amount of time on certain texts, a problem called catastrophic backtracking. The tool stops the test so your page keeps working. Simplify the pattern or make quantifiers more specific.

    What do the g, i, m, s, u, v and y flags do?

    g finds all matches, i ignores case, m makes ^ and $ work per line, s lets the dot match line breaks, u and v turn on Unicode mode (v is the newer one and cannot be used together with u), and y matches only at the starting position. The “Flags” table on this page explains each one.

    How do I use capture groups in a replacement?

    Put parentheses around part of the pattern, then refer to that part in the replacement as $1, $2 and so on, or as $<name> if you named it with (?<name>…). Use $& for the whole match and $$ for a literal dollar sign.

    Last updated: