Lua-如何查找具有1个或2个字符差异的子字符串 [英] Lua - How to find a substring with 1 or 2 characters discrepancy

查看:124
本文介绍了Lua-如何查找具有1个或2个字符差异的子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个字符串

local a = "Hello universe"

我发现

a:find("universe")

现在,假设字符串为

local a = "un#verse"

要搜索的字符串是Universe;但是子字符串的区别在于单个字符. 所以显然Lua忽略了它.

The string to be searched is universe; but the substring differs by a single character. So obviously Lua ignores it.

即使单个字符存在差异,如何使函数找到字符串?

How do I make the function find the string even if there is a discrepancy by a single character?

推荐答案

如果您知道字符在哪里,请使用.而不是该字符:a:find("un.verse")

If you know where the character would be, use . instead of that character: a:find("un.verse")

但是,您似乎正在寻找模糊字符串搜索.它不在Lua string库的范围内.您可能要从本文开始: http://ntz- developer.blogspot.com/2011/03/fuzzy-string-search.html

However, it looks like you're looking for a fuzzy string search. It is out of a scope for a Lua string library. You may want to start with this article: http://ntz-develop.blogspot.com/2011/03/fuzzy-string-search.html

关于Lua模糊搜索的实现-我还没有使用过,但是搜索"lua Fuzzy Search"会给出一些结果.有些是基于本文的:

As for Lua fuzzy search implementations — I haven't used any, but googing "lua fuzzy search" gives a few results. Some are based on this paper: http://web.archive.org/web/20070518080535/http://www.heise.de/ct/english/97/04/386/

尝试 https://github.com/ajsher/luafuzzy .

这篇关于Lua-如何查找具有1个或2个字符差异的子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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