fork(1) download
  1. import re
  2.  
  3. text = r'''
  4.  
  5. {{funcB|param1}}
  6. *some string*
  7. {{funcA|param2}}
  8. {{funcB|param3}}
  9. *some string2*
  10.  
  11. {{funcB|param4}}
  12. *some string3*
  13. {{funcAka|param5}}
  14. {{funcB|param6}}
  15. *some string4*
  16. '''
  17.  
  18. for n in (range(1,(text.count('funcB')+1))):
  19. text = re.sub(r'(?i)(\s*{{funcA(ka|)\s*\|\s*([^}]*)\s*}}\s*|){{funcB\s*\|\s*([^}]*)\s*}}\s*',
  20. lambda m: r"\n | funcA"+str(n)+r" = " + (m.group(3) or '') + "\n | funcB" + str(n) + r" = " + (m.group(4) or '') + "\n | string" + str(n) + r" = \n",
  21. text,
  22. count=1)
  23.  
  24. assert text == r'''
  25. | funcA1 =
  26. | funcB1 = param1
  27. | string1 =
  28. *some string*
  29. | funcA2 = param2
  30. | funcB2 = param3
  31. | string2 =
  32. *some string2*
  33. | funcA3 =
  34. | funcB3 = param4
  35. | string3 =
  36. *some string3*
  37. | funcA4 = param5
  38. | funcB4 = param6
  39. | string4 =
  40. *some string4*
  41. '''
  42. print 'ok'
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
ok