Regular Expressions 2 Flashcards

1
Q

What is a regular expression?

A

A regular expression, regex or regexp, is a sequence of characters that define a search pattern.

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

What does [A-Z] mean?

A

Any character from A to Z

e.g [0-9] 0,1,2..9
[a-d] a,b,c,d

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

What does \s mean?

A

Any whitespace character (tab \t, space, new-line \n)

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

What does \w mean?

A

Any alphanumeric character

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

What does \b mean?

A

Stands for a word boundary

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

What does \d mean?

A

Stands for a digit (= [0-9] )

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

What does {x,y} do?

A

{x,y} specifies the number of repeats of a previous item
a{1,3} matches a, aa ,and aaa, but not aaaa
a{1,} means 1 or more a

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

What does ^[ ] mean?

A

^ at the beginning [ ] matches all characters specified in the group at the start of a line or given sentence

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

What does [^ ] mean?

A

When [^inside brackets], it means “not”.

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

What does $ do?

A

$ matches the end of a text

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

What does ^ do?

A

^ matches the start of a text

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

What does . mean?

A

. (dot) is the wildcard symbol (any letter)

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

What does ? mean?

A

? specifies that the previous character is optional

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

What does + and * mean? And what are they called?

A
• + matches one or more of the preceding
character (or range)
• * matches zero or more of the preceding
character (or group)
• + and * are called (Kleene) closures
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does \D \S \W mean?

A

\D Any non-digit character, equivalent to [^0-9]
\S Any non-whitespace character, equivalent to [^\t\n\r\f\v]
\W Any non-alphanumeric character, equivalent to [^a-zA-Z0-9_]

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

What does \t \n mean?

A

\t The tab character

\n The newline character

17
Q

What does re.search(pattern, text) do?

A

Check whether exists any
match of the pattern in
the text

18
Q

What does re.split(pattern, text) do?

A

Splits the text according to

certain rules

19
Q

What does re.findall(pattern, text) do?

A

Finds all occurrences of

text matching the pattern