re.compile(r'([^a-zA-Z0-9])(%s)([^a-zA-Z0-9])' % '\+test', re.I)
A β+β is βrepeat at least onceβ in regular expressions. It must follow something that is repeatable, or it must be escaped if you want to combine the literal "+".
This is better if you want to dynamically build your regular expression.
re.compile(r'([^a-zA-Z0-9])(%s)([^a-zA-Z0-9])' % re.escape('+test'), re.I)
source share