我需要确定字符串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
我正在尝试以编程方式区分f1
和f2
失败模式,以找出字符串可能是潜在匹配的开始还是可以排除为被拒绝。
更新:我知道re.match
不会告诉我为什么它不匹配,我正在尝试找出如何以某种方式从基础引擎获取该信息