用lua模式在字符串中捕获序列

str = " for xxxx in (yyyy) do @ for xxxx in pairs(yyyy) do"
for cap in string.gmatch(str, "(for(.-)in(.*)do)") do
Print (cap)
end

在此代码中,xxxxyyyy 是变量。空格也是变量。因此我尝试捕获仅限于“ for xxxx in (yyyy)“。同时,我需要捕获“ for xxxx in pairs(yyyy) do”。

但我的模式都捕获了。请帮忙。

点赞