--- title: string.gmatch summary: 返回一个Lua模式匹配代;Lua模式与PCRE常规表达式不同. section: reference kind: api status: reference updated: 2026-10-26 tags: ["API","X4"] sources: ["https://wiki.egosoft.com/X4%20Foundations%20Wiki/Modding%20Support/","https://www.lua.org/manual/5.1/manual.html","https://luajit.org/ext_ffi_api.html"] --- ## 说明 返回一个Lua模式匹配代;Lua模式与PCRE常规表达式不同. ## 返回值 | 类型 | 含义 | | --- | --- | | [`function`](wiki:type-function) | 类型描述了声明的界面,而不是证明成功的游戏效果. | [类型与方法](wiki:types) ## 参数 | 名称 | 类型 | | --- | --- | | `text` | [`string`](wiki:type-string) | | `pattern` | [`string`](wiki:type-string) | 没有什么. 标志着可选的参数;... 表示可变的参点数. 无效输入可能会导致Lua错误,而不是返回零. ## 示例与上下文 ```lua for word in string.gmatch("ship station", "%a+") do local upper = string.upper(word) end ``` **运行效果:** 代器产生"船"和"站";上部变成"船"和"站". 这段段没有打印或写日志信息. 显示的值是示例的预期结果. 看到 [语言基础](wiki:x4-code-basics), [类型和方法](wiki:types) 和 [Lua / MD事件](wiki:md-lua-bridge). 其他独立学习的例子. 没有项目源文件或私人实施碎片被分配到此引用.