In a string (in reality it's much bigger):
s = """
BeginA
Qwerty
Element 11 35
EndA
BeginB
Element 12 38
...
Element 198 38
EndB
BeginA
Element 81132 38
SomethingElse
EndA
BeginB
Element 12 39
Element 198 38
EndB
"""
how to replace every Element <anythinghere> 38 which is inside a BeginB...EndB block (and only those!) by Element ABC?
I was trying with:
s = re.sub(r'Element .* 38', 'Element ABC', s)
but this doesn't detect if it's in a BeginB...EndB block. How to do this?