【发布时间】:2014-11-12 13:24:21
【问题描述】:
re.compile('(?<!\(\s*)SELECT.*?FROM')
我想在 python 2.6 中编译正则表达式,但编译时出错。
python中的re模块不支持*/+/?,在正则表达式的lookbehind中,长度未确定。
有人评论建议我使用正则表达式,这是一个第三方模块。但是,我无法在公司服务器中使用第三方。
有人可以帮我重写正则表达式吗?
Target: "( SELECT blablabla" <- This could not be matched.
" SELECT blablabla" <- This could be matched, I mean no matter how many whitespace in front of the SELECT the string will always be matched.
【问题讨论】:
-
您在后视中使用 \s*。它们的大小必须是固定的。
-
您不能有可变长度的后视。量词
*和*?可以是任意长度,因此是可变的,因此在python 中是不合法的。 -
@Jerry
regex模块支持可变长度的lookbehind。 -
给我们错误和你要编译的表达式示例!
-
所以你的意思是第三方进口在 python 中是非法的。
标签: python regex python-2.6 regular-language