Regex python2.7正则表达式中的连字符 模式=u ''[%-p>],这是因为在字符类的中间,>>pattern=ur'[%谢谢,它可以工作。仅在ASCII字符集中使用连字符?当我使用unicode字符串时,它会抛出'sre_常量。错误:错误字符范围'@LeoZhao:连字符前的字符/代码点需要低于其后的字符/代码点。[0-9]可以,[9-0]不是。@tim pietzcker感谢你在标题中指出我的问题。我已经纠正了。@anubhava,我没有足够的15点声誉来更改帖子分数。sorry@anubhava,我已经做到了。谢谢你的指导。这个标题毫无意义。这个问题太普遍了,我建议关闭并最终删除这篇文章。 >>> 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
如果将连字符放在最后或第一个位置,则其行为良好:Regex python2.7正则表达式中的连字符 模式=u ''[%-p>],这是因为在字符类的中间,>>pattern=ur'[%谢谢,它可以工作。仅在ASCII字符集中使用连字符?当我使用unicode字符串时,它会抛出'sre_常量。错误:错误字符范围'@LeoZhao:连字符前的字符/代码点需要低于其后的字符/代码点。[0-9]可以,[9-0]不是。@tim pietzcker感谢你在标题中指出我的问题。我已经纠正了。@anubhava,我没有足够的15点声誉来更改帖子分数。sorry@anubhava,我已经做到了。谢谢你的指导。这个标题毫无意义。这个问题太普遍了,我建议关闭并最终删除这篇文章。 >>> 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,regex,python-2.7,hyphen,Regex,Python 2.7,Hyphen,如果将连字符放在最后或第一个位置,则其行为良好: pattern = u'''[%-<]''' txt = '12 of 15 people run into the room' result = re.sub(pattern, ' ', txt) >> ' of people run into the room' >>>pattern=ur'[%谢谢,它可以工作。仅在ASCII字符集中使用连字符?当我使用unicode字符串时,它会抛出'sre_常量。错误:
pattern = u'''[%-<]'''
txt = '12 of 15 people run into the room'
result = re.sub(pattern, ' ', txt)
>> ' of people run into the room'
>>>pattern=ur'[%谢谢,它可以工作。仅在ASCII字符集中使用连字符?当我使用unicode字符串时,它会抛出'sre_常量。错误:错误字符范围'@LeoZhao:连字符前的字符/代码点需要低于其后的字符/代码点。[0-9]
可以,[9-0]
不是。@tim pietzcker感谢你在标题中指出我的问题。我已经纠正了。@anubhava,我没有足够的15点声誉来更改帖子分数。sorry@anubhava,我已经做到了。谢谢你的指导。这个标题毫无意义。这个问题太普遍了,我建议关闭并最终删除这篇文章。
>>> 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