Back to roadmaps regex Course

Regex Metacharacters and Flags Cheat Sheet

This quick reference guide covers all commonly used regex metacharacters, quantifiers, and flags.


1. Metacharacters and Shorthand Classes

Symbol Matches
. Any character except newline
\d Any digit (0-9)
\D Any non-digit
\w Any word character (a-z, A-Z, 0-9, _)
\W Any non-word character
\s Any whitespace character
\S Any non-whitespace character

2. Quantifiers

Symbol Meaning
* Zero or more
+ One or more
? Zero or one (optional)
{n} Exactly n times
{n,m} Between n and m times
*? / +? Lazy (non-greedy) version

3. Anchors and Assertions

Symbol Meaning
^ Start of string or line
$ End of string or line
\b Word boundary
(?=...) Positive lookahead
(?!...) Negative lookahead
(?<=...) Positive lookbehind
(?<!...) Negative lookbehind

4. Flags (JavaScript)

Flag Purpose
g Global — find all matches, not just the first
i Case-insensitive matching
m Multiline — ^ and $ match start/end of each line
s Dot-all — . also matches newlines
Published on Last updated: