–
正则测试 [root@master-10 /lua]#cat test.lua local list = '' local rfile = assert(io.open("/lua/a",'r')) for line in rfile:lines() do if not (string.match(line,"^%s*$")) then list = list.."|"..line end end list = string.gsub(list,"^%|",'') rfile:close() ngx.say(list,"</br>") local m, err = ngx.re.match("/2D/c.html", list,"i") if m then ngx.say(m[0]) else if err then ngx.log(ngx.ERR, "error: ", err) return end ngx.say("match not found") end [root@master-10 /lua]#cat a \.php$ \.html$ /[2-5]+/c\.html$ /([25]|d)+/c\.html$ 这里要使用perl语言风格的正则, string.match里面使用lua风格的正则
–
–
–
评论前必须登录!
注册