ngx.re.match
syntax: captures, err = ngx.re.match(subject, regex, options?, ctx?, res_table?) context: init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua* Matches the subject string using the Perl compatible regular expression regex with the optional options. Only the first occurrence of the match is returned, or nil if no match is found. In case of errors, like seeing a bad regular expression or exceeding the PCRE stack limit, nil and a string describing the error will be returned. When a match is found, a Lua table captures is returned, where captures[0] holds the whole substring being matched, and captures[1] holds the first parenthesized sub-pattern's capturing, captures[2] the second, and so on. local m, err = ngx.re.match("hello, 1234", "[0-9]+")
if m then
-- m[0] == "1234" else
if err then
ngx.log(ngx.ERR, "error: ", err)
return
end ngx.say("match not found")
end
local m, err = ngx.re.match("hello, 1234", "([0-9])[0-9]+")
-- m[0] == "1234"
-- m[1] == "1"
Named captures are also supported since the v0.7.14 release and are returned in the same Lua table as key-value pairs as the numbered captures. local m, err = ngx.re.match("hello, 1234", "([0-9])(?<remaining>[0-9]+)")
-- m[0] == "1234"
-- m[1] == "1"
-- m[2] == "234"
-- m["remaining"] == "234"
Unmatched subpatterns will have false values in their captures table fields. local m, err = ngx.re.match("hello, world", "(world)|(hello)|(?<named>howdy)")
-- m[0] == "hello"
-- m[1] == false
-- m[2] == "hello"
-- m[3] == false
-- m["named"] == false
Specify options to control how the match operation will be performed. The following option characters are supported: a anchored mode (only match from the beginning) d enable the DFA mode (or the longest token match semantics).
this requires PCRE 6.0+ or else a Lua exception will be thrown.
first introduced in ngx_lua v0.3.1rc30. D enable duplicate named pattern support. This allows named
subpattern names to be repeated, returning the captures in
an array-like Lua table. for example,
local m = ngx.re.match("hello, world",
"(?<named>\w+), (?<named>\w+)",
"D")
-- m["named"] == {"hello", "world"}
this option was first introduced in the v0.7.14 release.
this option requires at least PCRE 8.12. i case insensitive mode (similar to Perl's /i modifier) j enable PCRE JIT compilation, this requires PCRE 8.21+ which
must be built with the --enable-jit option. for optimum performance,
this option should always be used together with the 'o' option.
first introduced in ngx_lua v0.3.1rc30. J enable the PCRE Javascript compatible mode. this option was
first introduced in the v0.7.14 release. this option requires
at least PCRE 8.12. m multi-line mode (similar to Perl's /m modifier) o compile-once mode (similar to Perl's /o modifier),
to enable the worker-process-level compiled-regex cache s single-line mode (similar to Perl's /s modifier) u UTF-8 mode. this requires PCRE to be built with
the --enable-utf8 option or else a Lua exception will be thrown. U similar to "u" but disables PCRE's UTF-8 validity check on
the subject string. first introduced in ngx_lua v0.8.1. x extended mode (similar to Perl's /x modifier)

最新文章

  1. java中注解的使用与实例 (二)
  2. Apache与Nginx对客户端请求的处理机制对比
  3. Shopex4.85商派2014年商业模板和商业插件共600多套仅售600元送分销王2代SEO排名神具。
  4. Java用来进行批量文件重命名,批量提取特定类型文件
  5. Git 远程操作详解
  6. shell学习笔记(1)-变量
  7. 重温《js权威指南》 第7,8章
  8. js截取所需字符串长度
  9. Dijkstra in python
  10. SGU 194. Reactor Cooling(无源汇有上下界的网络流)
  11. php生成代金券码
  12. Android 中文API (70) —— BluetoothDevice[蓝牙]
  13. c# 【MVC】WebApi设置返回Json
  14. 【iOS 开发】Objective - C 面向对象 - 方法 | 成员变量 | 隐藏封装 | KVC | KVO | 初始化 | 多态
  15. Source-Based XSS Test Cases
  16. RestyCircuitBreaker --- openresty断路器
  17. MySQL三层结构、用户权限、索引设计原则
  18. Mybatis(一)入门介绍
  19. yum安装软件内容
  20. CocoaPods管理第三方

热门文章

  1. Java 微服务框架选型(Dubbo 和 Spring Cloud?)
  2. [论文阅读] Deep Residual Learning for Image Recognition(ResNet)
  3. transform做2d和3d变形(css动画一)
  4. Java高级篇(二)——网络通信
  5. linux下nginx负载均衡搭建
  6. 二 Djano模型层之模型字段选项
  7. 【JAVA】pdf转图片
  8. ASP.NET MVC-异常处理&amp;自定义错误页
  9. 将 Net 项目升级 Core项目经验:(二)修复迁移后Net Standard项目中的错误
  10. [ZJOI2008]泡泡堂