Reputation: 1607
I am stuck. I am trying to get rid of the tag and the whitespace between the tag using a regex.
b="<NAME>
content here
more content
</NAME>
"
result = re.sub("<NAME.*?NAME>", "", b)
If 'b' is all on one line it work. It removes everything between the name tags. But I need it to work with multiple lines as well.
Upvotes: 0
Views: 91
Reputation: 107287
Your regular expression is not correct. You can use the following regex:
In [7]: print(re.sub(r'\s*</?NAME>\s*', '', b))
content here
more content
or:
In [8]: print(re.sub(r'\s*</?NAME>\s*\n', '', b))
content here
more content
Upvotes: 1