Sample text: String -> content within the rev tag (via lxml).
I’m trying to remove the {{BLOCKS}} within the text.
I’ve used the following regex to remove simple, one line blocks:
p = re.compile('\{\{*.*\}\}')
nonBracketedString = p.sub('', bracketedString)
However this does not remove the first multi line bracketed section at the beginning of the content. How can one remove the multi-line, curly bracketed blocks?
EDIT:
Solution from answer:
p = re.compile('\{\{*?.*?\}\}', re.DOTALL)
nonBracketedString = p.sub('', bracketedString)
Set the dotall flag.
In the default mode,
.matches any character except a newline. If the DOTALL flag has been specified, this matches any character including a newline.http://docs.python.org/library/re.html
Also, you’ll need a non-greedy match between the brackets:
.*?