正则表达式相关函数 项目 描述 语法 capturestable, err ctyun.re.match(subject, regex, options?) 作用 正则匹配,返回匹配内容。 入参 subject:待匹配字符串。 regex:正则表达式。 options:控制如何执行匹配操作,支持以下选项: 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 ngxlua v0.3.1rc30. D enable duplicate named pattern support. This allows named subpattern names to be repeated, returning the captures in an arraylike 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 enablejit option. for optimum performance, this option should always be used together with the 'o' option. first introduced in ngxlua 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 multiline mode (similar to Perl's /m modifier) o compileonce mode (similar to Perl's /o modifier), to enable the workerprocesslevel compiledregex cache s singleline mode (similar to Perl's /s modifier) u UTF8 mode. this requires PCRE to be built with the enableutf8 option or else a Lua exception will be thrown. U similar to "u" but disables PCRE's UTF8 validity check on the subject string. first introduced in ngxlua v0.8.1. x extended mode (similar to Perl's /x modifier) 返回值 capturestable:找到匹配项时,返回一个lua table,其中capturestable[0]保存整个匹配的子字符串,capturestable[1]保存第一个带括号的子模式的捕获,capturestable[2]为第二个,以此类推。未找到匹配项时此项为nil。 err:描述错误信息的字符串。