Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. def iterate_tag(text_chunk, old_string, tagname):
  2. tag_re = r'(?:<[^>]*>)*'
  3.  
  4. full_regex = '(' + tag_re + ''.join(
  5. itertools.chain(*zip(
  6. map(re.escape, old_string),
  7. itertools.cycle([tag_re])))) + ')'
  8. curr_tag = '{tagname}'.format(tagname=re.escape(tagname))
  9. return re.sub(full_regex,
  10. '<START:' + curr_tag + '>' + r'1' + '<END:' + curr_tag + '>', text_chunk)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement