Lua 使用字符在表中查找值?

Lua 使用字符在表中查找值?,lua,Lua,我有一个包含值的表,我想从val表返回所有在搜索值中包含此字符的值 local items_array = { 'apple','app','hello', 'app21' } local function test(str) for k , v in pairs(items_array) do print(string.match( str, v ), v) // print(string.match( str, ".*"..v..".*" )) // it's don't

我有一个包含值的表,我想从val表返回所有在搜索值中包含此字符的值

local items_array = {
'apple','app','hello', 'app21'
}

local function test(str)
for k , v in pairs(items_array) do
    print(string.match( str, v ), v)
    // print(string.match( str, ".*"..v..".*" )) // it's don't work
end
end
test('a') // but that implies apple , app , app21
// returned

nil apple
nil app
nil hello
nil app21
您可以使用或检查表元素字符串是否包含搜索的字符串


请参阅Lua手册了解其基本内容。

我更新了问题代码。如果您不知道,string.find仅在查找单词已满时才起作用,如app==app。这在我的例子中不起作用。@pigger是的,这就是我要找的。谢谢