蟒蛇的新的正则表达式模块 https://pypi.python.org/pypi/regex支持模糊字符串匹配。大声歌颂(现在)。
根据文档:
The ENHANCEMATCH
标志进行模糊匹配尝试以提高拟合度
它找到的下一个匹配项。
The BESTMATCH
flag 使模糊匹配搜索最佳匹配
而不是下一场比赛
The ENHANCEMATCH
标志是使用设置的(?e)
as in
regex.search("(?e)(dog){e<=1}", "cat and dog")[1]
返回“狗”
但实际上没有什么设置BESTMATCH
旗帜。怎么样?
文档 https://pypi.python.org/pypi/regex on the BESTMATCH
标志功能是部分的(但正在改进)。 Poke-n-hope 表明BESTMATCH
设置使用(?b)
.
>>> import regex
>>> regex.search(r"(?e)(?:hello){e<=4}", "What did you say, oh - hello")[0]
'hat d'
>>> regex.search(r"(?b)(?:hello){e<=4}", "What did you say, oh - hello")[0]
'hello'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)