I am trying to match and replace all content tagged inside brackets with the following code:
content = 'Should replace [obj[text]obj] inside [loc[brackets]loc]'
pattern = re.compile(r"\[([A-Za-z0-9]+)(\[(.*?)\])([A-Za-z0-9]+)\]")
for match in pattern.finditer(content):
print(match.group(2))
re.sub(match.group(2), 'xxx', content)
However it keeps returning the very same original string. If I go like:
new=re.sub(match.group(2), 'xxx', content)
It returns something really random I can't still acount for. It gets me puzzled because the print in line 4 shows the findigs are correct.
Many thanks in advance.