Python Regex Cheatsheet
Python Regex Cheatsheet
Regular Expression Basics Regular Expression Character Classes Regular Expression Flags
. Any character except newline [ab-d] One character of: a, b, c, d i Ignore case
a The character a [^ab-d] One character except: a, b, c, d m ^ and $ match start and end of line
{2, 5} Between 2 and 5 \A Start of string, ignores m flag \YYY Octal character YYY
\B Non-word boundary
\g<Y> Insert match Y (name or number)
Regular Expression Groups
(?=...) Positive lookahead
\Y Insert group numbered Y
(...) Capturing group
(?!...) Negative lookahead
(?P<Y>...) Capturing group named Y
(?<=...) Positive lookbehind
(?:...) Non-capturing group
(?<!...) Negative lookbehind
\Y Match the Y'th captured group
(?()|) Conditional
(?P=Y) Match the named group Y
(?#...) Comment