如何找到最佳的模糊字符串匹配?

编程入门 行业动态 更新时间:2024-10-16 16:11:47
本文介绍了如何找到最佳的模糊字符串匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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 =" pypi.python/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'

更多推荐

如何找到最佳的模糊字符串匹配?

本文发布于:2023-10-23 05:29:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519928.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   模糊

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!