Lua 匹配字符串中所有小写字母的模式

Lua 匹配字符串中所有小写字母的模式,lua,Lua,我对模式很陌生。我想选择字符串jjjj,ae,和hii 我想匹配每个引用字符组中的所有小写字母 Str = [["1jjjjj" "Wae1" "Uhi2i"]] for X in string.gmatch(Str,'%".-[%l]([%l]*).-%"') do print(X) -- jjjjj, ae, hii end 给你。至少有一种方法可以做到: local str = [["1jjjjj" "Wae1" "Uhi2i"]] for word in str:gmatch(

我对模式很陌生。我想选择字符串
jjjj
ae
,和
hii

我想匹配每个引用字符组中的所有小写字母

Str = [["1jjjjj" "Wae1" "Uhi2i"]]
for X in string.gmatch(Str,'%".-[%l]([%l]*).-%"') do
    print(X) -- jjjjj, ae, hii
end

给你。至少有一种方法可以做到:

local str = [["1jjjjj" "Wae1" "Uhi2i"]]
for word in str:gmatch("%S+") do    
    local lowercase = ""

    for char in word:gmatch("%l") do
        lowercase = lowercase .. char
    end

    print(lowercase)
end

如果要保留小写字母,可以删除非小写字符


我假设您可以灵活地使用表来存储字符串,而不必解析单个字符串的引用部分。

请清晰准确。在测试中,你说你想要jj和hii,但在代码中,你说你想要打印jj和i。你想要什么?我想把括号里的所有小写字母都打印出来。至少有一种方法可以做到这一点:对于str:gmatch(“%S+”)中的单词,local str=[[“1jjjj”sjaj“Wae1”jaka“Uhi2i”]]对于word:gmatch(“%l”)中的字符,do local lowercase=”“do lowercase=lowercase。。char end print(小写)end//因此可能是错误的,因为在“是的,听起来很熟悉;)中需要更多的字母。如果它对您有效,请将答案标记为正确。
xs = {"1jjjjj", "Wae1", "Uhi2i"}
for _, x in ipairs(xs) do
    lowers = x:gsub("%L", "")
    print(lowers)
end
jjjjj
ae
hii