|
8 | 8 |
|
9 | 9 |
|
10 | 10 | def main(): |
11 | | - # Running `search` with "Hello" returns a `Match` object for first Hello |
| 11 | + # Running `search` with "Hello" has a match for first Hello |
12 | 12 | assert re.search(r"Hello", _TEXT_HELLO).start() == 6 |
13 | 13 |
|
14 | | - # Running `search` with "Hello$" returns a `Match` object for last Hello |
| 14 | + # Running `search` with "Hello$" has a match for last Hello |
15 | 15 | assert re.search(r"Hello$", _TEXT_HELLO).start() == 12 |
16 | 16 |
|
17 | | - # Running `findall` with "Hi \w+" returns a list of strings |
| 17 | + # Running `search` with "(Hello) (Hello)" has matches for Hello |
| 18 | + assert re.search(r"(Hello) (Hello)", _TEXT_HELLO).groups() == ("Hello", "Hello") |
| 19 | + |
| 20 | + # Running `findall` with "Hi \w+" has list of strings |
18 | 21 | assert re.findall(r"\w+", _TEXT_NAMES) == ["John", "Jane"] |
19 | 22 |
|
20 | | - # Running `match` with "[123]+" returns a `None` object |
| 23 | + # Running `match` with "[123]+" has nothing |
21 | 24 | assert re.match(r"[123]+", _TEXT_ABC123) is None |
22 | 25 |
|
23 | | - # Running `match` with "[abc]+" returns a `Match` object |
| 26 | + # Running `match` with "[abc]+" has a match for abc |
24 | 27 | assert re.match(r"[abc]+", _TEXT_ABC123).group(0) == "abc" |
25 | 28 |
|
26 | | - # Running `fullmatch` with "[\w]+" returns a `None` object |
| 29 | + # Running `fullmatch` with "[\w]+" has nothing |
27 | 30 | assert re.fullmatch(r"[\w]+", _TEXT_BYE) is None |
28 | 31 |
|
29 | | - # Running `fullmatch` with "[\w ]+" returns a `Match` object |
| 32 | + # Running `fullmatch` with "[\w ]+" has a full match |
30 | 33 | assert re.fullmatch(r"[\w ]+", _TEXT_BYE).group(0) == _TEXT_BYE |
31 | 34 |
|
32 | 35 | # There are many more ways to leverage regular expressions than what |
|
0 commit comments