fork download
  1. import re
  2.  
  3. line = r'#Совп. А# ... #Совп. Б# ... #Совп. В#'
  4.  
  5. def repl(x, count):
  6. count.i += 1
  7. return '<{0}>{1}</{0}>'.format(str(count.i),x.group())
  8.  
  9. obj = lambda:None
  10. obj.i =0
  11. line = re.sub(r'#[^#]*#', lambda x: repl(x, obj), line)
  12. print(line)
Success #stdin #stdout 0.02s 9524KB
stdin
Standard input is empty
stdout
<1>#Совп. А#</1> ... <2>#Совп. Б#</2> ... <3>#Совп. В#</3>