regex
Pattern-matching expressions for extracting, replacing or validating text.
Matching Basics
Core patterns to match common text elements.
Match any single character (except newline)
A pattern that matches any single character except for line breaks.
\. Match the start of a string
Anchors the pattern to the beginning of a string.
^Hello Match the end of a string
Anchors the pattern to the end of a string.
world$ Match any digit
Matches any numeric digit (0-9).
\d Match any non-digit
Matches any character that is not a digit.
\D Match any whitespace character
Matches any whitespace character (space, tab, newline, etc.).
\s Match any non-whitespace character
Matches any character that is not whitespace.
\S Match a word character
Matches letters (a-z, A-Z), numbers (0-9), and underscore (_).
\w Match a non-word character
Matches any character that is not a word character.
\W Match any newline
Matches a newline character.
\n Character Sets & Ranges
Patterns to specify a set of allowable characters or ranges.
Match a specific character set
Matches any character within the specified set of characters.
\[aeiou\] Match a range of characters
Matches characters within the specified range.
\[a-z\] Match any character except specified ones
Matches characters not in the specified set.
\[\^aeiou\] Match a character from a set or range
Matches any character that matches any of the patterns.
\[a-zA-Z0-9_\] Quantifiers
Specify how many times a pattern must occur.
Match zero or more times
Matches the preceding pattern zero or more times.
\* Match one or more times
Matches the preceding pattern one or more times.
+ Match zero or one time
Matches the preceding pattern zero or one time.
\? Match a specific number of times
Matches the preceding pattern an exact number of times.
\{3\} Match a range of times
Matches the preceding pattern within a range.
\{2,5\} Match at least n times
Matches the preceding pattern at least n times.
\{2,\} Groups and Lookaheads
Advanced patterns for grouping and conditional matches.
Group patterns together
Groups multiple patterns to treat them as a single unit.
(abc) Positive lookahead
Matches a group if it is followed by another pattern (but doesn't consume it).
(?=abc) Negative lookahead
Matches a group if it is not followed by another pattern (but doesn't consume it).
(?!abc) Capture groups
Captures matched text for reference or replacement.
(group) Non-capturing group
Groups patterns without capturing the matched text.
(?:abc) Named capture group
Captures matched text with a name.
(?<name>group) Positive lookbehind
Matches a group if it is preceded by another pattern (but doesn't consume it).
(?<=abc) Negative lookbehind
Matches a group if it is not preceded by another pattern (but doesn't consume it).
(?<!abc) Escaping Special Characters
Handling characters that have special meanings in regex.
Escape a special character
Matches the literal character instead of its special meaning.
\\ Match a literal dot
Matches the literal '.' character.
\. Match a literal asterisk
Matches the literal '*' character.
\* Match a literal plus sign
Matches the literal '+' character.
\+