regex Flashcards

1
Q

\w

A

alphanumeric values
r”[\w]ears” === __ears

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

”^”

A

matches the position at the beginning of string (unless used for negation “[ˆ]”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

”$”

A

matches the position at the end of string character.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

”?”

A

match preceding literal or sub- expression 0 or 1 times.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

”+”

A

match preceding literal or sub- expression one or more times.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

“*”

A

match preceding literal or sub- expression zero or more times

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

”.”

A

match any character except new line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

”[ ]”

A

match preceding literal or sub- expression zero or more times

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

”( )”

A

used to create a sub-expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

” \d “

A

match any digit character. “\D” is the complement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

” \w “

A

match any word character (letters, dig- its, underscore). “\W” is the comple- ment.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

“\s”

A

match any whitespace character in- cluding tabs and newlines. \S is the complement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

“*?”

A

Non-greedy version of *. Not fully discussed in class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

“\b”

A

match boundary between words. Not discussed in class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

”+?”

A

Non-greedy version of +. Not discussed in class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

“{m+n}”

A

The preceding element or subex- pression must occur between m and n times, inclusive

17
Q

re.split(pattern, string)

A

split
the string at substrings that match
the pattern. Returns a list.

18
Q

re.sub(pattern, replace, string)

A

apply the pattern to string replac-
ing matching substrings with replace.

Returns a string.

19
Q

re.findall(pattern, string)

A

Returns a list of all matches for the given
pattern in the string.