Vis*_*air 4 python regex python-2.7
我有以下 Python 正则表达式:
re =re.match(r'.*? from\s+(.*?)(\s.*|$)', q)
Run Code Online (Sandbox Code Playgroud)
这里,q 是这样的查询:
Q1 = u"select * from dlpx_jobs where job_id=\\'531\\';"
Q2 = u"select * FROM dlpx_jobs where job_id=\\'531\\';"
Run Code Online (Sandbox Code Playgroud)
现在,显然,对于 Q1,正则表达式有效,因为“from”在查询中是小写的,但对于 Q2,正则表达式不起作用,因为在 Q2 中,“from”是大写的。
无论“from”是大写还是小写,有什么方法可以使正则表达式同时适用于查询?
尝试这个:
expr = re.match(r'.? from\s+(.?)(\s.*|$)', q, re.IGNORECASE)
Run Code Online (Sandbox Code Playgroud)