Hello!
On Sun, Mar 3, 2013 at 9:44 PM, lhmwzy wrote:
> 像如下语句
> body1=[[
> <html>
> <table border="0" width="100%" cellspacing="0" cellpadding="0"
> class="TableLine" align="center">
> dsfkljsdf
> sdf
> sdf
> sdfs
> <form method=Post action="rl_SmallClass.asp?BName=>ldsfjksdlfkjsf
> sdfsdffsd
> </html>
> ]]
>
> local res=ngx.re.match(body1,[[<html>(.*)</html>]],"imjxd")
> 为啥没有匹配结果,我哪里写错了?
> error.log:
> attempt to index local 'res' (a nil value)
>
在 PCRE 默认模式下,正则中的圆点并不会匹配换行符。你需要指定 s 正则选项,即:
local res=ngx.re.match(body1,[[<html>(.*)</html>]],"is")
当然,同时指定 jo 选项是很好的习惯,可以极大地提升性能,即
local res=ngx.re.match(body1,[[<html>(.*)</html>]],"isjo")
你代码中的 xmd 都不是必须的。PCRE 的 DFA 模式并没什么性能上的优势。
Best regards,
-agentzh