如何找到最佳的模糊字符串匹配? [英] How can I find the best fuzzy string match?
问题描述
Python的新的正则表达式模块支持模糊字符串匹配.大声赞美(现在).
Python's new regex module supports fuzzy string matching. Sing praises aloud (now).
根据文档:
ENHANCEMATCH
标志进行模糊匹配尝试以提高拟合度 找到的下一个匹配项.
The
ENHANCEMATCH
flag makes fuzzy matching attempt to improve the fit of the next match that it finds.
BESTMATCH
标志使模糊匹配搜索最佳匹配
而不是下一场比赛
The BESTMATCH
flag makes fuzzy matching search for the best match
instead of the next match
与
regex.search("(?e)(dog){e<=1}", "cat and dog")[1]
返回狗"
,但是实际上没有设置BESTMATCH
标志.怎么样了?
but there's nothing on actually setting the BESTMATCH
flag. How's it done?
推荐答案
="a href =" https://pypi.python.org/pypi/regex"rel =" noreferrer>文档 c1>标志功能是部分的(但正在改进). Poke-n-hope显示使用(?b)
设置了BESTMATCH
.
Documentation on the BESTMATCH
flag functionality is partial (but improving). Poke-n-hope shows that BESTMATCH
is set using (?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'
这篇关于如何找到最佳的模糊字符串匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!