Hi I am trying to use regrex to replace everything surounded by "()" with an empty string "", but not in the case where "()" is in an angle bracket. e.g. "<..()>" should be ignored and not replaced. Example input:
Hi<Hi(now)>_(.)
Example output:
Hi<Hi(now)>_
Following what I read from answer
I have tried using the following method:
example = "Hi<Hi(now)>_(.)"
regex = re.compile(r"\<[^\>]*\>|(\([^\)]*\))")
re.sub(regex, '', str(first_p))
But it instead outputted
'Hi_'
Can anyone explain what might have gone wrong?