I’m a Python-regex newbie, so bear with me…
I have a long, multiline string, in which I have to replace the directory parts of [[…]] strings with other stuff, but ONLY IF they do not start with ‘file://’, so e.g.
s= 'chk1 [[file:///excursions/digital/MindMaps/|mm]],
local file [[file:///inFolder/tmptest/a/fan.txt|a/fan.txt]]
and nonlocal [[/excursions/books/calsync.txt|/excursions/books]]'
I used variations of this (at the moment the replace string is just a check of what I found):
re.sub('\[\[(?!file:)(^])*',"found:< \\1 >",s)
but I get a “sre_constants.error: unmatched group”. Do you know what I’m doing wrong?
thanks!
alessandro
You’re missing the
[]operator in the second group:should be
It’s also better to use raw strings when you have a lot of escaping: