Regex Syntax Reference

Search the forty rows by syntax, meaning or example, or read the table straight through. The notes mark where JavaScript, PCRE, Python, Java, .NET, Go and Ruby part ways.

Runs locally in your browser
SyntaxMeaningExample
\Escapes a metacharacter or starts a special sequence.\. matches a literal dot.
^Matches the start of the input, or the start of a line in multiline mode.^Error
$Matches the end of the input, or the end of a line in multiline mode.done$
i, m, s, u, xFlags placed after the closing delimiter: i ignores case, m lets ^ and $ match at line breaks, s makes . match line breaks as well, u switches JavaScript to Unicode mode, and x ignores unescaped whitespace and # comments in PCRE, Python, Java and Ruby./^done$/im
.Matches one character; line breaks are excluded unless dot-all mode is enabled.a.c
*Repeats the previous token zero or more times.ab*c
+Repeats the previous token one or more times.ab+c
?Makes the previous token optional.colou?r
{n}Repeats the previous token exactly n times.\d{4}
{n,}Repeats the previous token at least n times.\w{3,}
{n,m}Repeats the previous token from n through m times.[A-F0-9]{2,8}
*?, +?, ??Uses lazy repetition and consumes as little input as possible.<.*?>
*+, ++, ?+Possessive quantifiers: they match greedily and never give characters back, so the engine cannot backtrack into them. PCRE, Perl, Java and Python 3.11+ support them; JavaScript, Go and older Python releases do not.\d++
(?>pattern)Atomic group: the group keeps its first match and is not re-entered during backtracking. PCRE, .NET, Java, Perl and Python 3.11+ support it; JavaScript has no atomic groups.(?>a|ab)c
[abc]Matches one character from the set.gr[ae]y
[^abc]Matches one character that is not in the set.[^0-9]
[a-z]Matches one character in the specified range.[A-Za-z]
[[:alpha:]]POSIX character class inside a bracket expression, supported by PCRE, Java, Ruby and grep-style engines but not by JavaScript or Python, where the Unicode property escape is the portable spelling.[[:digit:]]+
x|yMatches the expression on the left or the expression on the right.cat|dog
(pattern)Groups a subexpression and captures its match.(ab)+
(?:pattern)Groups a subexpression without creating a capture.(?:https?)://
(?<name>pattern)Creates a named capture group where the engine supports it.(?<year>\d{4})
(?P<name>pattern)Named group spelling used by Python and by Go's RE2 engine, which accepts no backreference to the group.(?P<year>\d{4})
(?'name'pattern)Alternative named group spelling used by .NET, PCRE, Perl and Ruby; Java and JavaScript accept only the angle-bracket form.(?'year'\d{4})
\1Matches the same text captured by the first group.\b(\w+)\s+\1\b
\k<name>Backreference to a named group in JavaScript, .NET, PCRE, Java and Ruby; Python writes the P= form instead.(?<w>\w+)\s+\k<w>
(?=pattern)Positive lookahead: requires a following match without consuming it.\d+(?=px)
(?!pattern)Negative lookahead: requires that the following text does not match.foo(?!bar)
(?<=pattern)Positive lookbehind: requires a preceding match without consuming it.(?<=\$)\d+
(?<!pattern)Negative lookbehind: requires that the preceding text does not match.(?<!-)\b\d+
\A, \z, \ZAnchors for the very start or end of the string in PCRE, Python, Java and Ruby; the end-of-string form also allows a final line break there. JavaScript has no equivalent, so use ^ and $ without the m flag.\A\d{4}\z
\d / \DMatches a digit / a non-digit. Unicode behavior is engine-dependent.\d+
\w / \WMatches a word character / non-word character. The exact character set depends on the engine.\w+
\s / \SMatches whitespace / non-whitespace.\s+
\b / \BMatches a word boundary / a position that is not a word boundary.\bword\b
\n, \r, \tMatches a line feed, carriage return, or tab.\r?\n
\xNNMatches a character by its two-digit hexadecimal code unit.\x41 matches A.
\uNNNNMatches a character by a four-digit Unicode code unit in engines that support this notation.\u00A9 matches ©.
\u{1F600}, \x{1F600}Matches a code point above U+FFFF: JavaScript writes \u{...} with the u flag, while PCRE, Perl and Java write \x{...} and Python writes \U0001F600.\u{1F600}
\p{Letter}Matches a Unicode property when Unicode property escapes are supported and enabled.\p{Letter}+

How to look up a regex construct

Forty constructs in three columns: the syntax you type, what it does, and a short example. The rows cover the escapes, anchors, quantifiers, character classes, groups, lookarounds, flags and Unicode escapes that JavaScript, PCRE, Python, Java, .NET, Go and Ruby share, and they name the engines that reject an advanced form.

The page runs no pattern: nothing is compiled or matched here. The table ships with the page, the search field only hides rows in your browser, and nothing you type is sent anywhere.

  1. Type in the search field above the table to filter by syntax, meaning or example: lookbehind keeps the two lookbehind rows, \d keeps the ten rows that mention it, and Clear brings all forty rows back.
  2. Search reads plain text rather than a pattern, and it ignores case — lookbehind, Lookbehind and LOOKBEHIND return the same rows. A query that matches nothing shows the empty-state line instead of a blank table.
  3. Read across the row: the first column is what you type inside a pattern, the second says what it does, the third shows it in a short example.
  4. Press the copy button in the first cell to put that syntax token on the clipboard; the copied value is the token alone, for example *+, ++, ?+.
  5. Check the engine note before you use an advanced construct: the rows for possessive quantifiers, atomic groups, POSIX classes, \A \z \Z, named groups and \u{...} name the engines that accept them.

What the table covers

What the forty rows cover

Escapes (\d, \w, \b, \xNN, \uNNNN, \p{Letter}), anchors (^, $, \A, \z, \Z), greedy, lazy and possessive quantifiers, bracket expressions and POSIX classes, capturing and non-capturing groups, three spellings of named groups, backreferences, lookahead and lookbehind, inline flags, and code point escapes above U+FFFF.

Example cells are fragments rather than complete programs: \d++ and (?>a|ab)c show the construct in context, and the three rows that end in a sentence — \. matches a literal dot., \x41 matches A., \u00A9 matches ©. — read the way a pattern test would.

Where the engines disagree

Go's RE2 engine omits lookaround and backreferences; JavaScript has no atomic groups or possessive quantifiers and needs the u flag for \u{...} escapes; and a POSIX class such as [[:alpha:]] works in PCRE, Java, Ruby and grep-style engines but not in JavaScript or Python.

Python 3.11 and later accept atomic groups and possessive quantifiers, which PCRE, Perl and Java had earlier. Named groups are spelled (?P<name>...) in Python and RE2 and (?'name'...) in .NET, PCRE, Perl and Ruby; the named backreference is \k<name> except in Python, which writes (?P=name).

What the page does not do

It is a lookup table, not a tester: no pattern is compiled, nothing is matched against your text, and no code is generated. The tabs above carry the rest of the family — Regex Tester runs a pattern, Regex Code Generator writes it out for seven languages, Common Regex Patterns lists ready-made patterns.

The table is plain HTML and stays readable with JavaScript switched off; only the filter, the row count and the copy buttons need the script. Search matches the text on the page, so a query such as \d+ is read as the three characters it contains rather than as a pattern.

Recent tools: