regular expressions Flashcards

1
Q

module for regular expressions

A

re

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

?

A

match 0 or 1 repetitions of the preceding RE

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

make qualifiers not greedy

A

*?, +?, ??

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

match from m to n repetitions of the preceding RE, attempting to match as few repetitions as possible

A

{m,n}?

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

set of characters

A

[amk] [a-z] [0-9A-Fa-f] [^5]

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

named group

A

(?P…)

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

A backreference to a named group

A

(?P=name)

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

lookahead assertion

A

(?=…)

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

negative lookahead assertio

A

(?!…)

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

positive lookbehind assertion

A

(?<=…)

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

negative lookbehind assertion

A

(?

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

yes/no pattern

A

(?(id/name)yes-pattern|no-pattern)

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

Matches the contents of the group of the same number

A

\number

(.+) \1 matches ‘the the’ or ‘55 55’

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

Matches the empty string, but only at the beginning or end of a wor

A

\b

r’\bfoo\b’ matches ‘foo’, ‘foo.’, ‘(foo)’, ‘bar foo baz’ but not ‘foobar’ or ‘foo3’.

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

ompile a regular expression pattern into a regular expression objec

A

re.compile(pattern, flags=0)

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

Scan through string looking for the first location where the regular expression pattern produces a match, and return a corresponding match object.

A

re.search(pattern, string, flags=0)
Return None if no position in the string matches the pattern; note that this is different from finding a zero-length match at some point in the string.

17
Q

Split string by the occurrences of pattern.

A

re.split(pattern, string, maxsplit=0, flags=0)

18
Q

Return all non-overlapping matches of pattern in string, as a list of strings

A

re.findall(pattern, string, flags=0)

19
Q

Return an iterator yielding match objects over all non-overlapping matches for the RE pattern in string.

A

re.finditer(pattern, string, flags=0)

20
Q

get entire found string from match

A

m.group(0), m[0]

21
Q

Return the indices of the start and end of the substring matched by group

A

Match.start([group])

Match.end([group])