import re
text = r'''
{{funcB|param1}}
*some string*
{{funcA|param2}}
{{funcB|param3}}
*some string2*
{{funcB|param4}}
*some string3*
{{funcAka|param5}}
{{funcB|param6}}
*some string4*
'''
for n in (range(1,(text.count('funcB')+1))):
text = re.sub(r'(?i)(\s*{{funcA(ka|)\s*\|\s*([^}]*)\s*}}\s*|){{funcB\s*\|\s*([^}]*)\s*}}\s*',
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",
text,
count=1)
assert text == r'''
| funcA1 =
| funcB1 = param1
| string1 =
*some string*
| funcA2 = param2
| funcB2 = param3
| string2 =
*some string2*
| funcA3 =
| funcB3 = param4
| string3 =
*some string3*
| funcA4 = param5
| funcB4 = param6
| string4 =
*some string4*
'''
print 'ok'
aW1wb3J0IHJlCiAKdGV4dCA9IHInJycKIAp7e2Z1bmNCfHBhcmFtMX19Cipzb21lIHN0cmluZyoKe3tmdW5jQXxwYXJhbTJ9fQp7e2Z1bmNCfHBhcmFtM319Cipzb21lIHN0cmluZzIqCiAKe3tmdW5jQnxwYXJhbTR9fQoqc29tZSBzdHJpbmczKgp7e2Z1bmNBa2F8cGFyYW01fX0Ke3tmdW5jQnxwYXJhbTZ9fQoqc29tZSBzdHJpbmc0KgonJycKIApmb3IgbiBpbiAocmFuZ2UoMSwodGV4dC5jb3VudCgnZnVuY0InKSsxKSkpOgogICAgdGV4dCA9IHJlLnN1YihyJyg/aSkoXHMqe3tmdW5jQShrYXwpXHMqXHxccyooW159XSopXHMqfX1ccyp8KXt7ZnVuY0JccypcfFxzKihbXn1dKilccyp9fVxzKicsIAogICAgbGFtYmRhIG06IHIiXG4gfCBmdW5jQSIrc3RyKG4pK3IiID0gIiArIChtLmdyb3VwKDMpIG9yICcnKSArICJcbiB8IGZ1bmNCIiArIHN0cihuKSArIHIiID0gIiArIChtLmdyb3VwKDQpIG9yICcnKSArICJcbiB8IHN0cmluZyIg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