Unicode re.sub() doesn't work with \g<0> (group 0)
问题 Why doesn't the \g<0> work with unicode regex? When I tried to use \g<0> to insert a space before and after the group with normal string regex, it works: >>> punct = """,.:;!@#$%^&*(){}{}|\/?><"'""" >>> rx = re.compile('[%s]' % re.escape(punct)) >>> text = '''"anständig"''' >>> rx.sub(r" \g<0> ",text) ' " anst\xc3\xa4ndig " ' >>> print rx.sub(r" \g<0> ",text) " anständig " but with unicode regex, the space isn't added: >>> punct = u""",–−—’‘‚”“‟„!£"%$'&)(+*-€/.±°´·¸;:=<?>@§#¡•[˚]»_^`≤…\«¿¨{}|