I am trying to replace all expressions of the form
\[something\]
in a string by
\[<img src='something'>\]
Since \ and [ ] are special characters, I need to espace them (so \\, \[ and \]), thus my code would be
def repl(m):
return "<img src='"+m.group(1)+"'>"
print re.sub("\\\[(.*?)\\\]", repl, "frfrfr\nfrrffr<p>\[something\]</p>frff\nfrfrr", re.S)
However, this returns the original string. Could someone point out my mistake ?