openresty(lua-API-正则表达式)
摘自:http://www.daileinote.com/computer/openresty/10 ngx_lua 在表 ngx.re 里提供了5个正则表达式相关函数,它们的底层实现为 nginx 的 PCRE 库,并且支持 PCRE-JIT,速度非常快,完全可以代替 Lua 标准库的字符串匹配函数。 ngx.re.match1syntax: captures, err = ngx.re.match(subject, regex, options?, ctx?, res_table?) 返回第一个匹配,没匹配或报错返回 nil。 捕获的结果存在 captures 里,captures[0] 代表全部,captures[1] 代表第一个括号的捕获值,没捕获到的返回 nil。 1234567891011local m, err = ngx.re.match("hello, 1234", "[0-9]+")if m then -- m[0] == "1234"else if err then --出错 ...
