Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(3)  |  Call(3)  |  Derive(0)  |  Import(0)
Regular expression replacement. Target is either compiled re object or
string that will be compiled into one. Replacement is either string or
function that takes re match object as a parameter and returns replacement
string.

src/s/a/say-1.2.3/test/test_text.py   say(Download)
def test_re_replace():
    t = Text('a\nb\nc\nd')
    assert t.lines == 'a b c d'.split()
 
    t.re_replace(r'[b]', 'B')
    t.re_replace(r'd', lambda m: m.group(0).upper())
    assert t.lines == 'a B c D'.split()
 
    t1 = Text('and then there were none'.split())
    t1.re_replace(r'(?P<art>the)', lambda m: '*' + m.art.upper() + '*')