【发布时间】:2017-08-28 02:31:00
【问题描述】:
我有这个,不匹配,为什么?:
>>> p = r'abc'
>>> cp = re.compile(p, re.IGNORECASE)
>>> m = cp.search('ABC', re.IGNORECASE)
>>> m # NO MATCH # 1
但是,这给出了一个匹配,为什么?
>>> m = cp.search(' ABC', re.IGNORECASE) # introduced spaces, ABC no longer at the beginning
>>> m # MATCH # 2
<_sre.SRE_Match object at 0x1082b5ac0>
要在 #1 中获得匹配,我所要做的就是放弃 re.IGNORECASE,为什么会这样?
>>> m = cp.search('ABC')
>>> m
<_sre.SRE_Match object at 0x10827e308>
【问题讨论】:
标签: python regex python-2.7