示例#1
0
 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)
示例#2
0
 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)