def test_sub(self): exp = '(foo).*(bar)' text = 'foo is the opposite of bar' searched = re.search(exp, text) group = Group(text, searched) matches = group group.sub('zaz', 1) self.assertEqual('zaz', matches[0].replaced)
def test_sub_embedded(self): exp = '(foo (bar)).*(foo bar)' text = 'foo bar is grouped differently than foo bar' searched = re.search(exp, text) group = Group(text, searched) matches = group group.sub('zaz', 2) self.assertEqual('zaz', matches[0][1].replaced) expected = 'foo zaz is grouped differently than foo bar' self.assertEqual(expected, group.str)