aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/pyre2/py3/tests/test_sub.txt
blob: b41dd30d2813dd306f1b6b0bc4d6cdfcee73d416 (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
Tests of substitution
=====================

This first test is just looking to replace things between parentheses
with an empty string.


    >>> import hashlib
    >>> import gzip
    >>> import re2
    >>> re2.set_fallback_notification(re2.FALLBACK_EXCEPTION)
    >>> import warnings
    >>> warnings.filterwarnings('ignore', category=DeprecationWarning)

    >>> with gzip.open('tests/wikipages.xml.gz', 'rb') as tmp:
    ...     data = tmp.read()
    >>> print(hashlib.md5(re2.sub(b'\(.*?\)', b'', data)).hexdigest())
    b7a469f55ab76cd5887c81dbb0cfe6d3

    >>> re2.set_fallback_notification(re2.FALLBACK_QUIETLY)

Issue #26 re2.sub replacements with a match of "(.*)" hangs forever

   >>> re2.sub('(.*)', r'\1;replacement', 'original')
   'original;replacement;replacement'

   >>> re2.sub('(.*)', lambda x: x.group() + ';replacement', 'original')
   'original;replacement;replacement'

   >>> re2.subn("b*", lambda x: "X", "xyz", 4)
   ('XxXyXzX', 4)