Skip to main content

Regex Syntax Reference

v1.0.0

Searchable reference for regex patterns including character classes, quantifiers, anchors, groups, and lookaround.

38 entries found

.Character Classes

Any character except newline.

a.c → 'abc', 'a_c'
\dCharacter Classes

Digit — equivalent to [0-9].

\d+ → '123'
\DCharacter Classes

Non-digit.

\D+ → 'abc'
\wCharacter Classes

Word character — [a-zA-Z0-9_].

\w+ → 'hello_42'
\WCharacter Classes

Non-word character.

\W → ' ', '!'
\sCharacter Classes

Whitespace — space, tab, newline.

\s+ between words
\SCharacter Classes

Non-whitespace.

\S+ → 'hello'
[abc]Character Classes

Any character in the set.

[aeiou] → 'a', 'e'
[^abc]Character Classes

Any character NOT in the set.

[^aeiou] → consonants
[a-z]Character Classes

Any character in the range.

[a-z]+ → 'hello'
*Quantifiers

0 or more of the preceding element.

a* → '', 'a', 'aaa'
+Quantifiers

1 or more of the preceding element.

a+ → 'a', 'aaa'
?Quantifiers

0 or 1 of the preceding element — makes it optional.

colou?r → 'color', 'colour'
{n}Quantifiers

Exactly n repetitions.

\d{4} → '2024'
{n,}Quantifiers

At least n repetitions.

\d{3,} → '123', '1234'
{n,m}Quantifiers

Between n and m repetitions.

\d{2,4} → '12', '1234'
*? / +? / ??Quantifiers

Lazy (non-greedy) quantifiers — match as few as possible.

<.+?> matches inner tag only
^Anchors

Start of string (or line in multiline mode).

^Hello → 'Hello World'
$Anchors

End of string (or line in multiline mode).

end$ → 'the end'
\bAnchors

Word boundary — between \w and \W.

\bcat\b → 'cat' but not 'catch'
\BAnchors

Non-word boundary.

\Bcat → 'catch'
\AAnchors

Start of string (Python/not JS).

\ZAnchors

End of string (Python/not JS).

(abc)Groups

Capturing group — captures the match for back-references.

(ab)+ → 'ababab'
(?:abc)Groups

Non-capturing group — groups without capturing.

(?:https?://)\S+
(?<name>abc)Groups

Named capturing group.

(?<year>\d{4})-(?<month>\d{2})
\1 / \2Groups

Back-reference to capturing group 1, 2 etc.

(.)\1 → 'aa', 'bb'
a|bGroups

Alternation — matches a or b.

cat|dog → 'cat', 'dog'
(?=abc)Lookaround

Positive lookahead — asserts abc follows.

\d+(?= dollars)
(?!abc)Lookaround

Negative lookahead — asserts abc does NOT follow.

\d+(?! dollars)
(?<=abc)Lookaround

Positive lookbehind — asserts abc precedes.

(?<=\$)\d+
(?<!abc)Lookaround

Negative lookbehind — asserts abc does NOT precede.

(?<!\$)\d+
iFlags

Case-insensitive matching.

/hello/i → 'Hello', 'HELLO'
gFlags

Global — find all matches, not just the first.

/a/g → all 'a' in string
mFlags

Multiline — ^ and $ match start/end of each line.

/^hello/m
sFlags

Dotall — . matches newline too.

/.+/s
xFlags

Extended (verbose) — ignore whitespace, allow comments. (Python/Ruby)

/ # match digits
\d+/x
uFlags

Unicode mode — full Unicode matching (JS/Python).

/\p{L}+/u