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
29
30
31
32
33
34
35
36
|
Empty/unused groups
===================
>>> import re
>>> import re2
>>> re2.set_fallback_notification(re2.FALLBACK_EXCEPTION)
Unused vs. empty group:
>>> re.search( '(foo)?((.*).)(bar)?', 'a').groups()
(None, 'a', '', None)
>>> re2.search('(foo)?((.*).)(bar)?', 'a').groups()
(None, 'a', '', None)
>>> re.search(r'((.*)?.)', 'a').groups()
('a', '')
>>> re2.search(r'((.*)?.)', 'a').groups()
('a', '')
>>> re.search(r'((.*)+.)', 'a').groups()
('a', '')
>>> re2.search(r'((.*)+.)', 'a').groups()
('a', '')
The following show different behavior for re and re2:
>>> re.search(r'((.*)*.)', 'a').groups()
('a', '')
>>> re2.search(r'((.*)*.)', 'a').groups()
('a', None)
>>> re.search(r'((.*)*.)', 'Hello').groups()
('Hello', '')
>>> re2.search(r'((.*)*.)', 'Hello').groups()
('Hello', 'Hell')
>>> re2.set_fallback_notification(re2.FALLBACK_QUIETLY)
|