Literal Characters
Match exact characters.
abc # Matches "abc"
123 # Matches "123"
hello # Matches "hello"Metacharacters
Special characters with meaning.
. # Any character except newline
\d # Any digit [0-9]
\D # Any non-digit
\w # Word character [a-zA-Z0-9_]
\W # Non-word character
\s # Whitespace character
\S # Non-whitespace characterEscaping Special Characters
Use backslash to match literals.
\. # Matches literal period
\* # Matches literal asterisk
\? # Matches literal question mark
\\ # Matches literal backslash
\[ # Matches literal bracketAdvertisement
Alternation
Match one pattern or another.
cat|dog # Matches "cat" or "dog"
(red|blue|green) # Matches any color
yes|no # Matches "yes" or "no"Dot Metacharacter
Match any character.
a.c # Matches "abc", "a1c", "a@c"
... # Matches any 3 characters
h.t # Matches "hat", "hot", "h9t"Case Sensitivity
Regex is case-sensitive by default.
cat # Matches "cat" but not "Cat"
# Use flag for case-insensitive: /cat/iLiteral Strings
Match exact sequences.
hello world # Matches "hello world"
test123 # Matches "test123"Common Examples
Practical regex patterns.
\d\d\d-\d\d\d\d # Phone: 123-4567
\w+@\w+\.com # Simple email
https?://.* # URL starting with http/httpsLast updated: January 2026