关于Python正则表达式的区分大小写的问题
2010-05-23 23:36
681 查看
最近在用Python处理一些数据,数据需要存储到MySQL数据库中,采用MySQLdb来进行数据库的操作,但是被一个问题困扰了很久。在打开数据库的时候MySQLdb.connect(self.host, self.user, self.password, self.database, port=self.port)出异常,而且异常出现的位置非常奇怪。
出现在converters.py 164行
from decimal import Decimal
进去之后发现出错的位置在decimal.py文件中5833行出错
import re
_parser = re.compile(r""" # A numeric string consists of:
# /s*
(?P<sign>[-+])? # an optional sign, followed by either...
(
(?=/d|/./d) # ...a number (with at least one digit)
(?P<int>/d*) # having a (possibly empty) integer part
(/.(?P<frac>/d*))? # followed by an optional fractional part
(E(?P<exp>[-+]?/d+))? # followed by an optional exponent, or...
|
Inf(inity)? # ...an infinity, or...
|
(?P<signal>s)? # ...an (optionally signaling)
NaN # NaN
(?P<diag>/d*) # with (possibly empty) diagnostic info.
)
# /s*
/Z
""", re.VERBOSE | re.IGNORECASE | re.UNICODE).match
在编译正则表达式的时候出错,错误信息为
......
File "D:/Python27/lib/decimal.py", line 5850, in <module>
""", re.VERBOSE | re.IGNORECASE | re.UNICODE).match
File "D:/Python27/lib/re.py", line 190, in compile
return _compile(pattern, flags)
File "D:/Python27/lib/re.py", line 245, in _compile
raise error, v # invalid expression
sre_constants.error: internal: unsupported template operator
居然是系统库文件出错!
但我在其他地方调用MySQLdb.connect能够正常连接数据库,这就奇怪了,库文件的代码如果有问题应该总出错才对,所以排除了库文件代码的问题。
仔细对比了一下代码,没有发现有什么不同,连接过程都是一样的。
这个错误执行到编译正则表达式这一行应该和re模块有关系,仔细一想,我在代码里设置了re.IGNORECASE = True用来匹配的时候不区分大小写,将这一行注释掉之后在运行,果然异常消失了。看来这个东西还和IGNORECASE有关,只能区分大小写。
至此这个异常终于解决了,记录下来以备查看。
出现在converters.py 164行
from decimal import Decimal
进去之后发现出错的位置在decimal.py文件中5833行出错
import re
_parser = re.compile(r""" # A numeric string consists of:
# /s*
(?P<sign>[-+])? # an optional sign, followed by either...
(
(?=/d|/./d) # ...a number (with at least one digit)
(?P<int>/d*) # having a (possibly empty) integer part
(/.(?P<frac>/d*))? # followed by an optional fractional part
(E(?P<exp>[-+]?/d+))? # followed by an optional exponent, or...
|
Inf(inity)? # ...an infinity, or...
|
(?P<signal>s)? # ...an (optionally signaling)
NaN # NaN
(?P<diag>/d*) # with (possibly empty) diagnostic info.
)
# /s*
/Z
""", re.VERBOSE | re.IGNORECASE | re.UNICODE).match
在编译正则表达式的时候出错,错误信息为
......
File "D:/Python27/lib/decimal.py", line 5850, in <module>
""", re.VERBOSE | re.IGNORECASE | re.UNICODE).match
File "D:/Python27/lib/re.py", line 190, in compile
return _compile(pattern, flags)
File "D:/Python27/lib/re.py", line 245, in _compile
raise error, v # invalid expression
sre_constants.error: internal: unsupported template operator
居然是系统库文件出错!
但我在其他地方调用MySQLdb.connect能够正常连接数据库,这就奇怪了,库文件的代码如果有问题应该总出错才对,所以排除了库文件代码的问题。
仔细对比了一下代码,没有发现有什么不同,连接过程都是一样的。
这个错误执行到编译正则表达式这一行应该和re模块有关系,仔细一想,我在代码里设置了re.IGNORECASE = True用来匹配的时候不区分大小写,将这一行注释掉之后在运行,果然异常消失了。看来这个东西还和IGNORECASE有关,只能区分大小写。
至此这个异常终于解决了,记录下来以备查看。
相关文章推荐
- 关于Python正则表达式的问题
- 关于DataTable的Select方法参数表达式区分大小写的问题
- 关于Python正则表达式 findall函数问题详解
- 关于Python中正则表达式的反斜杠问题
- 关于MySQL区分大小写问题的探究
- Python中正则表达式对中文的匹配问题
- python正则表达式修复网站文章字体不统一问题
- Delphi 正则表达式语法(1): 关于大小写与中文
- iOS正则表达式之区分大小写中英文,判断输入框类型
- 关于JS 正则表达式验证问题
- Delphi 正则表达式语法: 关于大小写与中文
- python中关于正则表达式一
- selenium关于正则表达式匹配webdriver.Chrome().page_source中文的问题
- 关于正则表达式的递归匹配问题
- Delphi 正则表达式语法(1): 关于大小写与中文
- 关于c++中正则表达式的几个问题
- 正则表达式不区分大小写以及解决思路的探索 .
- Python中正则表达式对中文的匹配问题
- C#正则表达式的完全匹配、部分匹配及忽略大小写的问题
- 业务需要,得到了两段正则表达式的代码,JAVASCRIPT的(关于车牌号码的校验问题)。