|
Category
|
Expression
|
Description
|
Example (Before)
|
Example (After)
|
Basics
|
.
|
Any character except a newline
|
'hello world'
|
'h'
|
Basics
|
^
|
Start of a string
|
'hello world'
|
'hello'
|
Basics
|
$
|
End of a string
|
'hello world'
|
'world'
|
Basics
|
\
|
Escape special characters
|
'Cost: 100$'
|
'Cost: 100\$'
|
Character Classes
|
[abc]
|
Matches a, b, or c
|
'cat', 'bat', 'hat'
|
'c', 'b', 'h'
|
Character Classes
|
[^abc]
|
Negation: Matches anything except a, b, or c
|
'dog', 'bat', 'rat'
|
'd', 'r'
|
Character Classes
|
[a-z]
|
Matches any lowercase letter (a to z)
|
'apple', 'banana', 'grape'
|
'a', 'b', 'g'
|
Character Classes
|
[A-Z]
|
Matches any uppercase letter (A to Z)
|
'APPLE', 'BANANA', 'GRAPE'
|
'A', 'B', 'G'
|
Character Classes
|
[0-9]
|
Matches any digit (0 to 9)
|
'123', '456'
|
'1', '4'
|
Character Classes
|
[a-zA-Z0-9_]
|
Matches any alphanumeric character
|
'word1', 'word_2', 'word3'
|
'w', 'w', 'w'
|
Quantifiers
|
*
|
0 or more times (greedy)
|
'aaa', ''
|
'aaa'
|
Quantifiers
|
+
|
1 or more times (greedy)
|
'a', 'aa', 'aaa'
|
'a', 'aa', 'aaa'
|
Quantifiers
|
?
|
0 or 1 time (optional)
|
'a', ''
|
'a'
|
Quantifiers
|
{n}
|
Exactly n times
|
'aaa', 'a'
|
'aaa'
|
Quantifiers
|
{n,}
|
At least n times
|
'aa', 'aaa', 'aaaa'
|
'aa', 'aaa'
|
Quantifiers
|
{n,m}
|
Between n and m times
|
'aaa', 'aa'
|
'aaa', 'aa'
|
Grouping & Alternation
|
(abc)
|
Grouping: Matches abc and captures it
|
'abc', 'xyz'
|
'abc'
|
Grouping & Alternation
|
(?:abc)
|
Non-capturing group
|
'abc', 'xyz'
|
'abc'
|
Grouping & Alternation
|
a|b
|
Matches a or b
|
'a', 'b'
|
'a', 'b'
|
Assertions
|
(?=abc)
|
Positive lookahead: Ensures abc follows but doesn’t consume it
|
'abc123'
|
'123'
|
Assertions
|
(?!abc)
|
Negative lookahead: Ensures abc does NOT follow
|
'xyz123'
|
'xyz123'
|
Assertions
|
(?<=abc)
|
Positive lookbehind: Ensures abc precedes
|
'abc'
|
'abc'
|
Assertions
|
(?
|
Negative lookbehind: Ensures abc does NOT precede
|
'xyz'
|
'xyz'
|
Anchors & Word Boundaries
|
\b
|
Word boundary
|
' word '
|
' '
|
Anchors & Word Boundaries
|
\B
|
Not a word boundary
|
'word'
|
'w'
|
Common Escapes
|
\d
|
Any digit [0-9]
|
'123'
|
'1'
|
Common Escapes
|
\D
|
Any non-digit [^0-9]
|
'a'
|
'a'
|
Common Escapes
|
\w
|
Any word character [a-zA-Z0-9_]
|
'abc123'
|
'a', '1'
|
Common Escapes
|
\W
|
Any non-word character [^a-zA-Z0-9_]
|
'@#$%'
|
'@'
|
Common Escapes
|
\s
|
Any whitespace (spaces, tabs, newlines)
|
' space '
|
' '
|
Common Escapes
|
\S
|
Any non-whitespace
|
'word'
|
'word'
|
Common Examples
|
^\d{3}-\d{2}-\d{4}$
|
Matches SSN format (e.g., 123-45-6789)
|
'123-45-6789'
|
'123-45-6789'
|
Common Examples
|
\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b
|
Email validation
|
'user@example.com'
|
'user@example.com'
|
Common Examples
|
https?://\S+
|
Matches a URL
|
'http://example.com'
|
'http://example.com'
|
Common Examples
|
\b\d{3}-\d{3}-\d{4}\b
|
Matches phone number (123-456-7890)
|
'123-456-7890'
|
'123-456-7890'
|
|
|