def test_as_replace_function(self):
"""Test that replace can be used as a replace function."""
text = "this will be fed into re.subn! Here we go! this will be fed into re.subn! Here we go!"
text_pattern = r"(?P<first>this )(?P<second>.*?)(!)"
pattern = bre.compile_search(text_pattern)
replace = bre.compile_replace(pattern, r'\c\g<first>is awesome\g<3>')
result, count = pattern.subn(replace, text)
self.assertEqual(result, "This is awesome! Here we go! This is awesome! Here we go!")
self.assertEqual(count, 2)
评论列表
文章目录