博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ngx.re.match
阅读量:6197 次
发布时间:2019-06-21

本文共 3880 字,大约阅读时间需要 12 分钟。

ngx.re.matchsyntax: 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])(?
[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)|(?
howdy)") -- m[0] == "hello" -- m[1] == false -- m[2] == "hello" -- m[3] == false -- m["named"] == falseSpecify 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", "(?
\w+), (?
\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 caches 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)

转载于:https://www.cnblogs.com/xiangnan/p/6134783.html

你可能感兴趣的文章
分享Silverlight/WPF/Windows Phone/HTML5一周学习导读(2月6日-2月12日)
查看>>
微信公众号再归归类
查看>>
db2move 导入导出数据库
查看>>
Spring Security 之身份认证
查看>>
理解并演示:帧中继的逆向解析功能(frame-relay inverse-arp)
查看>>
华为数据中心:融合方案也分层次
查看>>
传统创业者给互联网创业者上了一课
查看>>
oracle监听错误与hosts文件配置
查看>>
SCOM2012部署系列之十五:配置电子邮件警报通知
查看>>
一篇软文是如何赚到10万的
查看>>
Lync 2013演示PPT提示证书出现问题的解决办法
查看>>
采用python的pyquery引擎做网页爬虫,进行数据分析
查看>>
京南数据中心目标直指云服务
查看>>
Linux下修改用户主目录与锁定上传目录
查看>>
Citrix桌面及应用虚拟化系列之二:XenServer补丁
查看>>
《Java从小白到大牛精简版》之第3章 第一个Java程序
查看>>
Android应用程序消息处理机制(Looper、Handler)分析(4)
查看>>
再谈软件开发过程
查看>>
智能家居时代:安全用水何以如此重要?
查看>>
Spread Studio中文支持图解
查看>>