python2.7 正则表达式中的连字符

hyphen in python2.7 regular expression

pattern = u'''[%-<]'''

txt = '12 of 15 people run into the room'

result = re.sub(pattern, ' ', txt)

>> '   of    people run into the room'

正则表达式怎么匹配到数字?

编辑:

创建的范围是

这是由于字符 class 中间的 未转义连字符 作为范围而发生的。

如果您将连字符放在最后或第一个位置,则它表现良好:

>>> pattern = ur'[%<-]'
>>> print re.sub(pattern, ' ', txt)
12 of 15 people run into the room

或使用转义连字符:

>>> pattern = ur'[%\-<]'
>>> print re.sub(pattern, ' ', txt)
12 of 15 people run into the room