I know in regex we can use ^
to declare something except. For example [^ ]*?
means a string with no space. How we can use this to find the except for more than two consecutive character. Fro example a string that doesn't contain {{
when it can contain a single {
. I tried these and didn't work:
re.compile(r"(\{\{`[^(\{\{)]*?\}\}`)
re.compile(r"(\{\{`[^\{\{]*?\}\}`)
This is to catch strings in a file that starts with {{
and ends with }}
but doesn't contains }}
while they can contain a single }
. Also using .*
is not an option.
input_string="blah blah blah {{cite journal |last=Malatesta|first=Errico|title=Towards Anarchism|journal=MAN!|publisher=International Group of San Francisco|location=Los Angeles|oclc=3930443|url=http://www.marxists.org/archive/malatesta/1930s/xx/toanarchy.htm|archiveurl=http://web.archive.org/web/20121107221404/http://marxists.org/archive/malatesta/1930s/xx/toanarchy.htm|archivedate=7 November 2012 |deadurl=no|authorlink=Errico Malatesta |ref=harv}} blah blah blah"
regexp_1 = re.compile(r"(\{\{[^\}]*?\}\})")
output = regexp_1.sub("",input_string )
Now regexp_1
, I want to replace [^\}]*?
with [^\}\}]*?
and I know that [^\}\}]*?
is not correct since it works the same way as [^\}]*?
.