Regular Expression Flashcards
1
Q
any character
A
.
2
Q
zero or more
A
*
3
Q
one or more
A
+
4
Q
whitespace (space, newline, tab)
A
\s
5
Q
two characters
A
\w{2}
6
Q
search for match
A
re. search(pattern, string) # at most one match
re. findall(pattern, string) # list of matches
7
Q
get first tuple from re.search
A
re.search(pattern, string).group(1) # 0 is full match
8
Q
beginning of line or string
A
9
Q
end of line or string
A
$
10
Q
all uppercase letters
A
[A-Z]
11
Q
a, b or c
A
[abc]
12
Q
not b
A
[^b]
13
Q
not lowercase letters
A
[^a-z]
14
Q
neither n or o
A
[^no]
15
Q
this or that
A
(this|that)