regular expressions Flashcards
module for regular expressions
re
?
match 0 or 1 repetitions of the preceding RE
make qualifiers not greedy
*?, +?, ??
match from m to n repetitions of the preceding RE, attempting to match as few repetitions as possible
{m,n}?
set of characters
[amk] [a-z] [0-9A-Fa-f] [^5]
named group
(?P…)
A backreference to a named group
(?P=name)
lookahead assertion
(?=…)
negative lookahead assertio
(?!…)
positive lookbehind assertion
(?<=…)
negative lookbehind assertion
(?
yes/no pattern
(?(id/name)yes-pattern|no-pattern)
Matches the contents of the group of the same number
\number
(.+) \1 matches ‘the the’ or ‘55 55’
Matches the empty string, but only at the beginning or end of a wor
\b
r’\bfoo\b’ matches ‘foo’, ‘foo.’, ‘(foo)’, ‘bar foo baz’ but not ‘foobar’ or ‘foo3’.
ompile a regular expression pattern into a regular expression objec
re.compile(pattern, flags=0)