我有以下正则表达式
^(.+?)(\s+engine$|\s+ROW_FORMAT)
启用了忽略大小写。
这个问题是,它匹配"引擎"或" row_format"并且两者都不匹配(如last example所示)。我在这里缺少什么?
In [17]: st = 'this is my engine and row_format'
In [18]: match = re.match('^(.+?)(\s+engine$|\s+ROW_FORMAT)', st, re.I)
In [19]: match
Out[19]: <_sre.SRE_Match at 0x26c5030>
In [20]: match.group(1)
Out[20]: 'this is my'
In [21]: st = 'this is my row_format and engine'
In [22]: match = re.match('^(.+?)(\s+engine$|\s+ROW_FORMAT)', st, re.I)
In [23]: match.group(1)
Out[23]: 'this is my'
In [24]: match.group(2)
Out[24]: ' row_format'
In [25]: match.group(3)
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-25-da7df187e689> in <module>()
----> 1 match.group(3)
IndexError: no such group
答案 0 :(得分:3)
添加特殊字符Model
;这causes the resulting RE to match 1 or more repetitions of the preceding RE
Model