Unicode Icon Characters
Regex Cheatsheet
Python Regex Basics
| . | Any character except newline | |
| \d | Digit [0-9] | |
| \D | Non-digit | |
| \w | Word char [a-zA-Z0-9_] | |
| \W | Non-word char | |
| \s | Whitespace [ \t\n\r\f\v] | |
| \S | Non-whitespace | |
| \b | Word boundary | |
| ^ | Start of string / line | |
| $ | End of string / line |
Quantifiers
| * | 0 or more (greedy) | |
| + | 1 or more (greedy) | |
| ? | 0 or 1 (optional) | |
| {n} | Exactly n times | |
| {n,} | n or more times | |
| {n,m} | Between n and m times | |
| *? | 0 or more (lazy) | |
| +? | 1 or more (lazy) |
Groups & Lookaround
| (abc) | Capturing group | |
| (?:abc) | Non-capturing group | |
| (?P<name>abc) | Named group (Python) | |
| \1 | Backreference to group 1 | |
| a|b | Alternation (a or b) | |
| (?=abc) | Positive lookahead | |
| (?!abc) | Negative lookahead | |
| (?<=abc) | Positive lookbehind | |
| (?<!abc) | Negative lookbehind |
Character Classes
| [abc] | Any of a, b, or c | |
| [^abc] | Not a, b, or c | |
| [a-z] | Range a to z | |
| [0-9] | Range 0 to 9 | |
| [a-zA-Z] | Any letter | |
| [a-zA-Z0-9_] | Word character (same as \w) |
Python re Module
| re.search(p, s) | First match anywhere in string | |
| re.match(p, s) | Match at start of string | |
| re.fullmatch(p, s) | Match entire string | |
| re.findall(p, s) | List of all matches | |
| re.finditer(p, s) | Iterator of match objects | |
| re.sub(p, r, s) | Replace matches with r | |
| re.split(p, s) | Split string by pattern | |
| re.compile(p) | Compile pattern for reuse |
Python re Flags
| re.IGNORECASE | Case-insensitive matching (re.I) | |
| re.MULTILINE | ^ and $ match each line (re.M) | |
| re.DOTALL | . matches newline too (re.S) | |
| re.VERBOSE | Allow comments in pattern (re.X) |
Common Regex Patterns
| ^[\w.-]+@[\w.-]+\.\w+$ | Email address | |
| ^https?://[^\s]+$ | URL (http/https) | |
| ^\d{1,3}(\.\d{1,3}){3}$ | IPv4 address | |
| ^\d{4}-\d{2}-\d{2}$ | Date YYYY-MM-DD | |
| ^\+?\d{7,15}$ | Phone number (intl) | |
| ^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$ | Hex color code | |
| ^(?=.*[A-Z])(?=.*\d).{8,}$ | Password (8+, upper, digit) | |
| \b\d+\.\d+\b | Decimal number |
SQLAlchemy Connection Strings
| sqlite:///app.db | SQLite (relative path) | |
| sqlite:////abs/path/app.db | SQLite (absolute path) | |
| sqlite:///:memory: | SQLite in-memory | |
| postgresql://user:pass@host:5432/db | PostgreSQL (psycopg2) | |
| postgresql+psycopg2://user:pass@host/db | PostgreSQL explicit driver | |
| postgresql+asyncpg://user:pass@host/db | PostgreSQL async | |
| mysql+pymysql://user:pass@host:3306/db | MySQL (PyMySQL) | |
| mysql+mysqlconnector://user:pass@host/db | MySQL (connector) | |
| mysql+aiomysql://user:pass@host/db | MySQL async | |
| mariadb+pymysql://user:pass@host/db | MariaDB | |
| mssql+pyodbc://user:pass@host/db?driver=... | SQL Server (pyodbc) | |
| mssql+pymssql://user:pass@host/db | SQL Server (pymssql) | |
| oracle+cx_oracle://user:pass@host:1521/sid | Oracle |
SQLAlchemy Connection Options
| create_engine(url, echo=True) | Enable SQL logging | |
| create_engine(url, pool_size=10) | Set connection pool size | |
| create_engine(url, max_overflow=20) | Extra connections beyond pool | |
| create_engine(url, pool_recycle=3600) | Recycle connections (seconds) | |
| create_engine(url, pool_pre_ping=True) | Test connections before use | |
| create_async_engine(url) | Async engine (asyncio) | |
| URL.create("postgresql", ...) | Build URL programmatically |