This cheat sheet is a comprehensive guide to the most common regular expression patterns, syntax, and constructs. Use it as a quick reference for your regex development.
. - Any character except newline\w, \d, \s - Word, digit, whitespace\W, \D, \S - Not word, digit, whitespace[abc] - Any of a, b, or c[^abc] - Not a, b, or c[a-g] - Character between a & g[0-9] - Any digit from 0 to 9[a-z] - Any lowercase letter from a to z[A-Z] - Any uppercase letter from A to Z^ - Start of string$ - End of string\b - Word boundary\B - Not a word boundary\A - Start of string (for multiline)\Z - End of string (for multiline)* - 0 or more repetitions (e.g., a* matches "", "a", "aa", etc.)+ - 1 or more repetitions (e.g., a+ matches "a", "aa", etc.)? - 0 or 1 repetition (e.g., a? matches "" or "a"){5} - Exactly 5 repetitions{5,} - 5 or more repetitions{5,10} - Between 5 and 10 repetitions*?, +?, ??, {n,}? - Non-greedy quantifiers(abc) - Capture group\1 - Backreference to group #1(?:abc) - Non-capturing group| - Alternation (or)(?=...) - Positive lookahead(?!...) - Negative lookahead(?<=...) - Positive lookbehind(? - Negative lookbehind[:upper:] - Uppercase letters[:lower:] - Lowercase letters[:alpha:] - All letters[:alnum:] - Digits and letters[:digit:] - Digits[:xdigit:] - Hexadecimal digits[:punct:] - Punctuation[:blank:] - Space and tab[:space:] - Blank characters[:cntrl:] - Control characters[:graph:] - Printed characters[:print:] - Printed characters and spaceg - Global searchi - Case-insensitive searchm - Multiline searchs - Dotall mode, where . matches newline charactersu - Unicode supporty - Sticky mode