Advertisement
Guest User

eem_regex.py

a guest
Jun 16th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import  re
  2.  
  3. SRC = 'no event manager applet test\nevent manager applet test\n event none\n action 1010 if 1 eq 1\n action 1020  set i 1\n action 1030 end\n! end_applet\n'
  4.  
  5. NO_APPLET = ''
  6. LABEL = '^ action \d{4}'
  7. LABEL_START = 10
  8. LABEL_STEP = 10
  9.  
  10. print(SRC)
  11.  
  12. dst = ''
  13. label = LABEL_START
  14. repl = ' action ' + '{:04d}'.format(label)
  15. # repl = 'action ' + str(label)
  16.  
  17. # prog = re.compile(LABEL)
  18. # result = prog.match(string)
  19.  
  20. for line in SRC.splitlines():
  21.     newline, i = re.subn(LABEL, repl, line)
  22.     # re.subn(pattern, repl, string, count=0, flags=0)
  23.     if i > 0:
  24.         label = label + LABEL_STEP
  25.         # repl = ' action ' + format('{%4d}', label)
  26.         repl = ' action ' + '{:04d}'.format(label)
  27.         # repl = 'action ' + str(label)
  28.  
  29.     dst = dst + newline + '\n'
  30.  
  31. print(dst)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement