Regex Tester

Type a regular expression and some text to see every match highlighted, with its groups and positions. Matching uses your browser's JavaScript engine, and your text stays on your device.

Flags

Matches


Match details

Explanation

      Code

      
        

        How to use the regex tester

        1. Type your pattern into Regular expression, without the surrounding slashes, or pick one from Common patterns, which also loads sample text.
        2. Tick the Flags you need. For example, g finds every match instead of only the first.
        3. Paste your text into Test string. Matches are highlighted as you type, and Match details lists each match with its position and the value and position of every group.
        4. Read the Explanation to check each part of the pattern does what you meant. Mistakes such as Python-only syntax are shown in red.
        5. Choose Replace to preview a substitution. Use $1 or $<name> for groups and $& for the whole match.
        6. Under Code, pick JavaScript, Python or PHP and click Copy code. The pattern and flags are in the page address, so you can bookmark or share them; the test string is not.

        What the regex tester does

        It runs your regular expression against your text and shows the result four ways: highlighted matches, a table of matches and groups, a token-by-token explanation of the pattern, and ready-to-run code in JavaScript, Python and PHP.

        Matching uses your browser's own JavaScript engine, the same RegExp that runs in your code. It follows the ECMAScript standard (ECMA-262), so a pattern that works here works in other browsers and Node.js versions that support the same features. It is not PCRE or Python's re module, and some syntax differs; see the comparison below. Matching runs in a background worker and is stopped after 1.5 seconds, so a runaway pattern cannot freeze the page. Up to 1,000 matches are highlighted and the first 200 are listed in the table.

        Regex cheat sheet

        TokenMatches
        .Any character except a line break (any character at all with s)
        \d \w \sA digit 0–9; a word character (A–Z, a–z, 0–9, _); whitespace
        \D \W \SAnything except a digit, word character or whitespace
        [abc] [^abc] [a-z]One of a, b or c; anything except them; a range
        \p{L} \p{Lu}Any letter; an uppercase letter (needs u or v)
        ^ $Start and end of the text (of each line with m)
        \b \BA word boundary; not a word boundary
        * + ?0 or more; 1 or more; 0 or 1 (greedy: as many as possible)
        {3} {2,} {2,5}Exactly 3; 2 or more; 2 to 5
        *? +? {2,5}?Lazy versions: as few as possible
        (…) (?<name>…)Capturing group; named capturing group
        (?:…)Group without capturing
        \1 \k<name>Backreference: the same text a group matched
        (?=…) (?!…)Lookahead: followed by, not followed by
        (?<=…) (?<!…)Lookbehind: preceded by, not preceded by
        a|ba or b
        \. \* \/A literal dot, asterisk or slash

        In a replacement string, $1 inserts group 1, $<name> a named group, $& the whole match and $$ a dollar sign. The flags are g (all matches), i (ignore case), m (multiline anchors), s (dot matches line breaks), u and v (Unicode modes; use one, not both), y (sticky: match at the current position only) and d (record group positions in match.indices). This page always records positions, so the table shows them with or without d.

        Worked example

        Pick ISO date from Common patterns. The pattern is \b(?<year>\d{4})-(?<month>0[1-9]|1[0-2])-(?<day>0[1-9]|[12]\d|3[01])\b with the g flag, and the test string is:

        Released 2026-11-18, patched 2026-12-01. Not dates: 2026-13-01, 26-11-18

        There are 2 matches. 2026-11-18 runs from position 9 to 19, with year 2026 at 9–13, month 11 at 14–16 and day 18 at 17–19. 2026-12-01 runs from 29 to 39. 2026-13-01 fails because the month group allows only 01–12, and 26-11-18 fails because the year needs four digits. Switch to Replace with $<day>/$<month>/$<year> and the preview reads Released 18/11/2026, patched 01/12/2026. followed by the unchanged rest. Turn off g and only the first date matches.

        The pattern checks the shape of a date, not the calendar: 2026-02-31 still matches. Check real dates in code after matching.

        JavaScript, PCRE (PHP) and Python compared

        FeatureJavaScriptPHP (PCRE2)Python re
        Named group(?<name>…)(?<name>…), (?'name'…) or (?P<name>…)(?P<name>…)
        Possessive a++, atomic (?>…)Not supportedSupportedSupported from Python 3.11
        Lookbehind lengthAny lengthFixed length per alternative; variable length up to 255 characters from PCRE2 10.43 (bundled in PHP 8.4+)Fixed length only
        \A, \ZNot anchors: without u they match the letters A and Z; with u they are errorsStart; end or before a final newline (\z is the very end)Start; very end of the text
        $ without multilineVery end onlyAlso before a final newline, unless the D modifier is setAlso before a final newline
        \p{…}With u or vSupportedNot in re
        Find all matchesg flagpreg_match_allfinditer or findall
        Group in a replacement$1, $<name>$1, 1, \1\1, \g<1>, \g<name>

        The Code panel applies these differences where it can: it rewrites named groups to (?P<name>…) for Python, turns $ into \Z for Python and adds the D modifier for PHP, always adds PHP's u modifier and rewrites \d and \w as ASCII ranges to match JavaScript, spells out JavaScript's . (which also excludes \r) as a class, converts $<name> replacements to group numbers for PHP's preg_replace (which has no named references), and lists anything it cannot translate. In Python, \d and \w match non-ASCII digits and letters by default; JavaScript's match ASCII only.

        Catastrophic backtracking

        A backtracking engine tries every way a pattern could match before giving up. Nested quantifiers such as ^(a+)+$ give it an exponential number of ways to split the text, and each extra character roughly doubles the work: on a string of 30 as followed by !, there are more than 500 million ways to try, so this page stops the run at its 1.5-second limit. JavaScript has no possessive quantifiers or atomic groups to prevent this, so rewrite the pattern instead: ^a+$ matches the same strings. If a run is stopped here, look for a quantified group that contains another quantifier, or alternatives that can match the same text.

        Common mistakes

        Key terms

        Regular expression
        A pattern that describes a set of strings, used to search, validate, extract or replace text. Also called a regex. In JavaScript it is a RegExp object, written as /pattern/flags or new RegExp("pattern", "flags").
        Capturing group
        A part of a regular expression in parentheses, such as (\d+), whose matched text is saved and numbered from 1 by the position of its opening parenthesis. You can use it in the match result, a backreference or a replacement such as $1.
        Named capturing group
        A capturing group with a name, written (?…) in JavaScript and (?P…) in Python. Its text is available by name, as match.groups.name in JavaScript or $ in a replacement, and it is still numbered like any other group.
        Quantifier
        A token that says how many times the item before it may repeat: * (0 or more), + (1 or more), ? (0 or 1) or {min,max}. By default quantifiers are greedy and match as much as they can.
        Lazy quantifier
        A quantifier followed by ?, such as *? or +?, that matches as few repetitions as possible and only takes more if the rest of the pattern fails. Also called non-greedy or reluctant.
        Lookaround
        An assertion that checks the text ahead of or behind the current position without including it in the match: lookahead (?=…) and (?!…), and lookbehind (?<=…) and (?
        Backreference
        A token such as \1 or \k that matches the same text a capturing group already matched. (\w)\1 finds a doubled character such as the ll in hello.
        Regex flag
        A letter after the closing slash that changes how the whole pattern works, such as g (find all matches), i (ignore case) or m (multiline). JavaScript has g, i, m, s, u, v, y and d.
        Catastrophic backtracking
        Extremely slow matching caused by a pattern that gives a backtracking engine an exponential number of ways to try, usually through nested quantifiers like (a+)+. A short input can hang a page or a server, which is why this tester runs patterns with a time limit.

        Frequently asked questions

        Which regex flavor does this tester use?
        JavaScript's, as built into your browser and defined by the ECMAScript standard. Patterns behave the same as RegExp in browsers and Node.js. For Python or PHP, the Code panel converts what it can and notes what differs.
        Can it generate a regex for me?
        It does not write a pattern from examples. It does have ready-made common patterns (email, URL, IPv4, ISO date, UUID, hex color and slug) that you can load and adapt, and it generates the code to use any pattern in JavaScript, Python or PHP.
        Why does my pattern only find one match?
        The g flag is off. Without it JavaScript stops after the first match, and replace changes only the first occurrence. Tick g in Flags to find them all.
        Why does (?P<name>...) give an error?
        That is Python's named-group syntax. JavaScript writes named groups as (?...) and refers to them with \k in the pattern or $ in a replacement.
        What does "Stopped after 1,500 ms" mean?
        The pattern took longer than 1.5 seconds on your text, so the background worker was stopped to keep the page responsive. This is almost always catastrophic backtracking from nested or overlapping quantifiers; simplifying the pattern usually fixes it.
        Is the email pattern good enough to validate addresses?
        It is a simplification that finds most everyday addresses in text. It rejects some valid but unusual forms and accepts some addresses that do not exist, so confirm an address by sending a message to it.
        Is my test text uploaded?
        No. Matching runs in your browser, in a background worker on your device. The pattern, flags and replacement go into the page address so you can share a link, but the test string does not.
        What is the difference between the u and v flags?
        Both make the pattern Unicode-aware, so an emoji counts as one character and \p{…} works. The v flag also allows set operations in classes, such as [\p{L}--[a-z]] for letters other than a to z. You can use one or the other, not both.

        Sources: ECMA-262: RegExp objects, MDN: Regular expressions, Python: re, PCRE2 pattern syntax, PHP: preg_replace. Last checked 2026-11-18.