aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/pyre2/py3/tests/test_emptygroups.txt
blob: 424c8ba25e08d4fc07281b6ca7862dd7b07e4634 (plain) (blame)
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)