26 terms

Regular expressions Python

STUDY
PLAY
\d
Any numeric digit
\D
Any character that is not a number
\w
Any number, letter, or underscore
\W
Any character that is not a number, letter, or underscore
|
Match OR
?
Optional matching character
*
Matches zero or all of preceding group
+
Matches at least one or more of the preceding group
{}
Matches specific repetitions
{}?
Makes specific repetition matching non greedy
\s
Any tab, space, or new line
\S
Anything that is not a tab, space, or new line
()
group
[]
DIY Character class composition
^
Negative character class when combined with brackets
^
Symbol that states match must occur at beginning of strjng
$
Symbol that states match must occur at end of string
.
Wildcard that matches any character except a new line
.*
Match Any and all characters
.*?
All characters non greedy
r
Declares a string to be raw
findall()
Method that Returns a list if regex does not include groups, returns tuples if the regex does contain groups
re.compile()
First method of compiling regexs
re.I
Ignores case if passed as second argument of re.compile
re.DOTALL
Ignore new line characters if passed as a second argument of re.compile('.*')
re.VERBOSE
Allows re.compile() to be spread across multiple lines if used as the second argument.
YOU MIGHT ALSO LIKE...