1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
Simple tests for the ``finditer`` function.
===========================================
>>> import re2
>>> re2.set_fallback_notification(re2.FALLBACK_EXCEPTION)
>>> with open('tests/cnn_homepage.dat') as tmp:
... data = tmp.read()
>>> len(list(re2.finditer(r'\w+', data)))
14230
>>> [m.group(1) for m in re2.finditer(r'\n#hdr-editions(.*?)\n', data)]
[' a { text-decoration:none; }', ' li { padding:0 10px; }', ' ul li.no-pad-left span { font-size:12px; }']
>>> [m.group(1) for m in re2.finditer(r'^#hdr-editions(.*?)$',
... data, re2.M)]
[' a { text-decoration:none; }', ' li { padding:0 10px; }', ' ul li.no-pad-left span { font-size:12px; }']
>>> for a in re2.finditer(r'\b', 'foo bar zed'): print(a)
<re2.Match object; span=(0, 0), match=''>
<re2.Match object; span=(3, 3), match=''>
<re2.Match object; span=(4, 4), match=''>
<re2.Match object; span=(7, 7), match=''>
<re2.Match object; span=(8, 8), match=''>
<re2.Match object; span=(11, 11), match=''>
>>> re2.set_fallback_notification(re2.FALLBACK_QUIETLY)
|