regex Flashcards

(33 cards)

1
Q

Digit

regex

2 alternatives

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

a or b

regex

A
(a|b)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Group

regex

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

Range (a or b or c)

regex

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

Not (a or b or c)

A
[^abc]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Lower case letter from a to q

A
[a-q]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Upper case letter from A to Q

A

[A-Q]

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

Digit from 0 to 7

A

[0-7]

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

Look-ahead assertions

A

?=

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

Negative look-ahead

A

?!

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

Look-behind assertion

A

?<=

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

Negative look-behind

A

?!=
?<!

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

Any character except new line

A

.

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

0 or more

A

*

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

1 or more

A

+

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

Exactly 3

17
Q

3 or more

18
Q

3, 4, or 5

19
Q

Not digit

21
Q

Not word

22
Q

White space

23
Q

Not white space

24
Q

Start of string or line

25
Start of string
\A
26
End of string or line
\$
27
End of string
\Z
28
Word boundary
\b
29
Not word boundary
\B
30
Octal character xxx
\xxx
31
Hex character hh
\xhh
32
Use regular expressions
import re matches = re.findall(r'\b\d+\b', text)
33
Cleaning adresses
import re def clean_address(address): pattern = r'\d+\s+(?:[A-Z][a-z]+\s+)+' # Match street address part match = re.search(pattern, address) if match: return match.group(0).title() # Return it capitalized else: return address # Leave it as is if no match