Unicode Icon Characters

Regex Cheatsheet

Python Regex Basics

.Any character except newline
\dDigit [0-9]
\DNon-digit
\wWord char [a-zA-Z0-9_]
\WNon-word char
\sWhitespace [ \t\n\r\f\v]
\SNon-whitespace
\bWord 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)
\1Backreference to group 1
a|bAlternation (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.IGNORECASECase-insensitive matching (re.I)
re.MULTILINE^ and $ match each line (re.M)
re.DOTALL. matches newline too (re.S)
re.VERBOSEAllow 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+\bDecimal number

SQLAlchemy Connection Strings

sqlite:///app.dbSQLite (relative path)
sqlite:////abs/path/app.dbSQLite (absolute path)
sqlite:///:memory:SQLite in-memory
postgresql://user:pass@host:5432/dbPostgreSQL (psycopg2)
postgresql+psycopg2://user:pass@host/dbPostgreSQL explicit driver
postgresql+asyncpg://user:pass@host/dbPostgreSQL async
mysql+pymysql://user:pass@host:3306/dbMySQL (PyMySQL)
mysql+mysqlconnector://user:pass@host/dbMySQL (connector)
mysql+aiomysql://user:pass@host/dbMySQL async
mariadb+pymysql://user:pass@host/dbMariaDB
mssql+pyodbc://user:pass@host/db?driver=...SQL Server (pyodbc)
mssql+pymssql://user:pass@host/dbSQL Server (pymssql)
oracle+cx_oracle://user:pass@host:1521/sidOracle

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