检索 OpenResty Lua 中的正则表达式位置?

Retrieve regex location inside OpenResty Lua?

如何获取与 OpenResty / Nginx Lua 模块中的正则表达式位置匹配的部分?

例如我想在Lua中使用</code>,在下面的情况下:</p> <pre><code>location ~ ^/example/([0-9]+)/ { content_by_lua_block { -- What to use for ? ngx.say("Code: " .. (ngx.var.1 + 1)) } }

访问 /example/1234/.

时预期的行为将是 Code: 1235

ngx.var.1替换为ngx.var[1]

来自Lua参考手册:

The syntax var.Name is just syntactic sugar for var["Name"]

但是,它仅适用于字符串键。

来自 OpenResty 手册:

Nginx regex group capturing variables </code>, <code>, </code>, and etc, can be read by this interface as well, by writing <code>ngx.var[1], ngx.var[2], ngx.var[3], and etc.