Catalog / Regular Expressions Cheat Sheet
Regular Expressions Cheat Sheet
A concise reference for regular expressions, covering syntax, metacharacters, common patterns, and usage examples for efficient text processing.
Regex Basics and Metacharacters
Core Metacharacters
|
Escapes a special character (e.g., |
|
Matches any single character except newline. |
|
Matches the start of the string or line (depending on multiline mode). |
|
Matches the end of the string or line (depending on multiline mode). |
|
Acts as an ‘or’ operator (e.g., |
|
Defines a character class (e.g., |
Quantifiers
|
Matches the preceding character zero or more times. |
|
Matches the preceding character one or more times. |
|
Matches the preceding character zero or one time (optional). |
|
Matches the preceding character exactly n times. |
|
Matches the preceding character n or more times. |
|
Matches the preceding character between n and m times (inclusive). |
Character Classes
|
Matches any digit (0-9). |
|
Matches any non-digit character. |
|
Matches any word character (a-z, A-Z, 0-9, and _). |
|
Matches any non-word character. |
|
Matches any whitespace character (space, tab, newline). |
|
Matches any non-whitespace character. |
Anchors and Grouping
Anchors
|
Matches the beginning of the string. Inside a character class, it negates the class (e.g., |
|
Matches the end of the string. |
|
Matches a word boundary (the position between a word character and a non-word character). |
|
Matches a non-word boundary. |
Grouping and Capturing
|
Groups parts of a regex together. Captures the matched group for backreferencing. |
|
Creates a non-capturing group. Useful for grouping without capturing the matched text. |
|
Backreferences to the first, second, etc., captured groups in the regex. |
Flags/Modifiers
|
Case-insensitive matching. |
|
Global matching (find all matches rather than stopping after the first). |
|
Multiline mode: |
|
Dotall mode: |
Lookarounds and Common Patterns
Lookarounds
|
Positive lookahead: Matches if |
|
Negative lookahead: Matches if |
|
Positive lookbehind: Matches if |
|
Negative lookbehind: Matches if |
Common Patterns
Email Address: |
URL: |
IP Address: |
Date (YYYY-MM-DD): |
Phone Number (US): |
POSIX Character Classes
POSIX Character Classes
|
Alphanumeric characters (a-z, A-Z, 0-9). |
|
Alphabetic characters (a-z, A-Z). |
|
Space and tab characters. |
|
Control characters. |
|
Numeric characters (0-9); equivalent to |
|
Visible characters (excluding spaces, control characters). |
|
Lowercase characters (a-z). |
|
Printable characters (including spaces). |
|
Punctuation characters. |
|
Whitespace characters (space, tab, newline, etc.); equivalent to |
|
Uppercase characters (A-Z). |
|
Hexadecimal digits (0-9, a-f, A-F). |