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

时间:2019-04-22 01:34:20

标签: lua

我对模式非常陌生。我想拾取字符串jjjjjaehii

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

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

2 个答案:

答案 0 :(得分:1)

您在这里。一种方法,至少:

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

答案 1 :(得分:1)

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

xs = {"1jjjjj", "Wae1", "Uhi2i"}
for _, x in ipairs(xs) do
    lowers = x:gsub("%L", "")
    print(lowers)
end
jjjjj
ae
hii

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

相关问题