RE模块错误已解决.

下面这个错误是由于在正则[...]的内部,减号'-'是一个有特殊含义的字符(代表字符范围)

所以如果需要在[...]内匹配减号'-',需要用反斜杠'\'转义.

 

>>> import re
>>> re.split(r'[+\-*/%]','+a-b-c')
['', 'a', 'b', 'c']


>>> re.split(r'[+-*/%]','+a-b-c') Traceback (most recent call last): File "<pyshell#15>", line 1, in <module> re.split(r'[+-*/%]','+a-b-c') File "C:\Python27\lib\re.py", line 167, in split return _compile(pattern, flags).split(string, maxsplit) File "C:\Python27\lib\re.py", line 242, in _compile raise error, v # invalid expression error: bad character range

 

 

posted @ 2013-11-06 22:20  LisPythoniC  阅读(945)  评论(0编辑  收藏  举报