如何找到最佳的模糊字符串匹配? [英] How can I find the best fuzzy string match?

查看:129
本文介绍了如何找到最佳的模糊字符串匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆