regex_cheat_sheet
regex_cheat_sheet
1. Basic Patterns
^ Start of line
$ End of line
2. Character Classes
[abc] One of a, b, or c
[^abc] Not a, b, or c
[a-z] Lowercase a to z
[A-Z] Uppercase A to Z
[0-9] Digit 0 to 9
3. Special Sequences
\d Any digit
Regular Expressions Cheat Sheet
\D Non-digit
\W Non-word character
\S Non-whitespace
| OR
(pattern) Grouping
\w vs [a-zA-Z0-9_]: Equivalent
\s vs [ \t\n\r\f\v]: Equivalent
Example Codes:
import re
goodbye world"""
re.findall(r'\Agoodbye', text) # []
Useful Sites:
- https://regex101.com
- https://regexr.com