Regular Expression Flashcards Preview

INF3331 > Regular Expression > Flashcards

Flashcards in Regular Expression Deck (32)
Loading flashcards...
1

any character

.

2

zero or more

*

3

one or more

+

4

whitespace (space, newline, tab)

\s

5

two characters

\w{2}

6

search for match

re.search(pattern, string) # at most one match
re.findall(pattern, string) # list of matches

7

get first tuple from re.search

re.search(pattern, string).group(1) # 0 is full match

8

beginning of line or string

^

9

end of line or string

$

10

all uppercase letters

[A-Z]

11

a, b or c

[abc]

12

not b

[^b]

13

not lowercase letters

[^a-z]

14

neither n or o

[^no]

15

this or that

(this|that)

16

any word character

\w
[a-zA-Z0-9_]

17

any digit

\d

18

any non-word character

\W

19

any non-digit

\D

20

any non-whitespace character

\S

21

word boundary

\b (not inside [])

22

no word boundary

\B

23

special characters that need quoting

. | [ ( * ^ / { ?

24

optional minus-sign

-?

25

non-greedy .*

.*?

26

name a group

(?P\d)
match.group('number')

27

split string

re.split(r"\s+", str)

28

ignore case

re.search(pattern, string, re.IGNORECASE)

29

re.MULTILINE

^ and $ matches beginning and end of line

30

let . match newline characters

re.DOTALL