I think you have two errors. First, you are not escaping punct
like in the first example with re.escape
and you have characters like []
that need to be escaped. And second, text
variable is not unicode. Example that works:
>>> punct = re.escape(u""",–−—’‘‚”“‟„!£"%$'&)(+*-€/.±°´·¸;:=<?>@§#¡•[˚]»_^`≤…\«¿¨{}|""")
>>> rx = re.compile("["+"".join(punct)+"]", re.UNICODE)
>>> text = u"""„anständig“"""
>>> print rx.sub(ur" \g<0> ", text)
„ anständig “