subject
Hi,点是代表除了换行符以外的任意字符,但是在gsub里(.*)却是可以将换行符捕获到的。 # ./bin/resty -e 'local news,n,err = ngx.re.gsub("test line one\r\ntest line two\r\n",[=[^(.*)line one(.*)$]=],"${1}replace${2}","jom");ngx.say(news)'test replacetest line two但是在match里却无法捕获到。./bin/resty -e 'local m,err = ngx.re.match("test line one\r\ntest line two\r\n",[=[^(.*)line one(.*)$]=],"jom");ngx.say(m[1]);ngx.say(m[2])'test 本来打算使用[.\n]来捕获所有字符,但是却不生效,只能使用[\s\S]来捕获所有字符。/bin/resty -e 'local m,err = ngx.re.match("test line one\r\ntest line two\r\n",[=[^(.*)line one([\s\S]*)$]=],"jom");ngx.say(m[1]);ngx.say(m[2])'test test line two哪位对这里面的“猫腻”了解啊,帮忙解惑下。Thanks. --
re.* 用 pcre 规则https://github.com/openresty/lua-nginx-module#ngxrematchMatches the subject string using the Perl compatible regular _expression_Lance 2016-07-27 16:41 GMT+08:00 Guanglin Lv <any...@qq.com>:Hi,点是代表除了换行符以外的任意字符,但是在gsub里(.*)却是可以将换行符捕获到的。 # ./bin/resty -e 'local news,n,err = ngx.re.gsub("test line one\r\ntest line two\r\n",[=[^(.*)line one(.*)$]=],"${1}replace${2}","jom");ngx.say(news)'test replacetest line two但是在match里却无法捕获到。./bin/resty -e 'local m,err = ngx.re.match("test line one\r\ntest line two\r\n",[=[^(.*)line one(.*)$]=],"jom");ngx.say(m[1]);ngx.say(m[2])'test 本来打算使用[.\n]来捕获所有字符,但是却不生效,只能使用[\s\S]来捕获所有字符。/bin/resty -e 'local m,err = ngx.re.match("test line one\r\ntest line two\r\n",[=[^(.*)line one([\s\S]*)$]=],"jom");ngx.say(m[1]);ngx.say(m[2])'test test line two哪位对这里面的“猫腻”了解啊,帮忙解惑下。Thanks. --