2

我对模式很陌生。我想拿起琴弦jjjjj,aehii.

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

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

2 回答 2

1

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

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

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

于 2019-04-22T12:06:52.103 回答
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
于 2019-04-22T02:01:51.430 回答