string.gmatch()

类型 函数
string.*
返回值 模式查找迭代器
修订 版本 2024.3703
关键词 字符串,匹配,模式,gmatch
另请参阅 string.find()
string.gsub()
string.match()

概述

返回一个模式查找迭代器。有关更多信息,请参阅 Lua 字符串操作

语法

string.gmatch( s, pattern )

s:gmatch( pattern )
s (必填)

字符串 要搜索的字符串。

pattern (必填)

字符串 指定要匹配模式的字符串。有关更多信息,请参阅 Lua 字符串操作

示例

-- Collect all key-value pairs from the given string into a table
t = {}
s = "from=world, to=Lua"
for k, v in string.gmatch( s, "(%w+)=(%w+)" ) do
    t[k] = v
end