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
| Token | Matches |
|---|---|
. | Any character except a line break (any character at all with s) |
\d \w \s | A digit 0–9; a word character (A–Z, a–z, 0–9, _); whitespace |
\D \W \S | Anything 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 \B | A 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|b | a 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
| Feature | JavaScript | PHP (PCRE2) | Python re |
|---|---|---|---|
| Named group | (?<name>…) | (?<name>…), (?'name'…) or (?P<name>…) | (?P<name>…) |
Possessive a++, atomic (?>…) | Not supported | Supported | Supported from Python 3.11 |
| Lookbehind length | Any length | Fixed length per alternative; variable length up to 255 characters from PCRE2 10.43 (bundled in PHP 8.4+) | Fixed length only |
\A, \Z | Not anchors: without u they match the letters A and Z; with u they are errors | Start; end or before a final newline (\z is the very end) | Start; very end of the text |
$ without multiline | Very end only | Also before a final newline, unless the D modifier is set | Also before a final newline |
\p{…} | With u or v | Supported | Not in re |
| Find all matches | g flag | preg_match_all | finditer 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
- Double escaping in strings:
new RegExp("\d")is the patternd, because the string drops the backslash. Writenew RegExp("\\d")or use a literal,/\d/. - Greedy
.*:<.*>on<b>x</b>matches the whole string. Use<.*?>or<[^>]*>. - Reusing a
goryregex:test()andexec()continue fromlastIndex, so callingre.test(s)twice on the same string can return true then false.