Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def iterate_tag(text_chunk, old_string, tagname):
- tag_re = r'(?:<[^>]*>)*'
- full_regex = '(' + tag_re + ''.join(
- itertools.chain(*zip(
- map(re.escape, old_string),
- itertools.cycle([tag_re])))) + ')'
- curr_tag = '{tagname}'.format(tagname=re.escape(tagname))
- return re.sub(full_regex,
- '<START:' + curr_tag + '>' + r'1' + '<END:' + curr_tag + '>', text_chunk)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement