Basic Regex syntax.
|
.
|
Wildcard
|
|
^
|
Start of a string
|
|
$
|
End of a string
|
|
x*
|
0+ repetitions of x
|
|
x+
|
1+ repetitions of x
|
|
x?
|
0-1 repetitions of x
|
|
x{m}
|
m repetitions of x
|
|
x{m,n}
|
m-n repetitions of x, greedy
|
|
x{m,n}?
|
m-n repetitions of x, non-greedy
|
|
x|y
|
x OR y
|
|
[^x]
|
NOT x
|
|
\a
|
Literal 'a'
|
|
x*{int}
|
'x*' must be int long
|
|
< x > < y >
|
Collocations of x and y
|
|
<x> (<y>)
|
Only returns y
|
|
\n
|
newline
|
|
\s
|
space
|
|
\t
|
tab
|
|
\e
|
escape
|
|
\r
|
return
|
|
search()
|
Somewhere in string
|
|
findall()
|
Somewhere in the string, non-overlapping
|
|
match()
|
Beginning of string
|
|
fullmatch()
|
Entire string
|
|
\A
|
IS at start of string
|
|
\b
|
IS at wordbreak
|
|
\B
|
NOT at wordbreak
|
|
\d
|
IS [0-9]
|
|
\D
|
NOT [0-9]
|
|
\s
|
White space characters
|
|
\S
|
NOT white space characters
|
|
\w
|
IS Unicode word character [a-ZA-Z0-9_]
|
|
\W
|
NOT Unicode word character
|
|
\Z
|
IS at end of string
|
|
'{:n}'.format(x)
|
Prints x, padded with n whitespace
|
|
{:<n}
|
Left justified
|
|
{:>n}
|
Right justified
|
|
{:.nf}
|
Show n decimal places
|
|
'{:{width}}'.format('x', width=n)
|
|
|
1
|
Parenthesis
|
( )
|
|
2
|
Counters
|
* + ? { }
|
|
3
|
Sequences and anchors
|
^ $
|
|
4
|
Disjunction
|
|
|
|
re.I
|
re.IGNORECASE
|
|
|
re.M
|
re.MULTILINE
|
^ $ match line boundaries
|
|
re.X
|
re.VERBOSE
|
Ignores whitespace
|
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.