Skip to main content

Regex Syntax Reference

v1.0.1

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

Complete reference for regular expression syntax — character classes, quantifiers, anchors, groups, lookaheads, backreferences, and flags — across JavaScript, Python, Java, Go, and PCRE flavours, with copy-ready examples.

How to use
  • Search by token or concept (e.g. "lookahead", " word boundary", "non-greedy") to jump to its entry.
  • Select a language flavour from the dropdown to highlight syntax differences specific to that engine.
  • Click any example to copy it for use in your code, pre-formatted for the selected language.
  • Use the Flags section to see what /g, /i, /m, /s, /u, and /v do before adding them to your pattern.

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