以编程方式确定Python的re.match在哪里停止匹配

时间:2019-10-28 23:39:04

标签: python regex

我需要确定字符串re.match中停止匹配的位置;举一个简单的例子:

import re
abc = re.compile(r"[ab]+c$")

m = abc.match("baac")
# Matches, yay!

f1 = abc.match("badc")
# Match fails at index 2
# I.e. the string is actively rejected

f2 = abc.match("babb")
# Match fails after the end of the string
# I.e. the string is consumed before a match is accepted, but it wasn't rejected

我正在尝试以编程方式区分f1f2失败模式,以找出字符串可能是潜在匹配的开始还是可以排除为被拒绝。

更新:我知道re.match不会告诉我为什么它不匹配,我正在尝试找出如何以某种方式从基础引擎获取该信息

0 个答案:

没有答案