On Wed, May 16, 2012 at 10:01 PM, Sparsh Gupta <spars...@gmail.com> wrote:
> I am using Lua gmatch function as per documentation. I dont want the
> parts but just want to see if there was a match or not. I am getting
> back a Lua Iterator but I dont think iterating over it to find if
> match was found or not is the best way. Any other recommendation.
Use ngx.re.match instead of ngx.re.gmatch. See
> if rows then
> local url, n = ngx.re.gsub(ngx.var.arg_u,
> "$1$2$3", "i")
> for i, row in ipairs(rows) do
> local iterator = ngx.re.gmatch(url, row["urls"], "i")
> -- HERE I want to check if match happened or not?
> Also, the regex is working fine with PHP and PERL (and bash egrep) but
> not working here and throwing error:
> 2012/05/16 13:59:11 [error] 4754#0: *655 Failed to load Lua inlined
> code: [string "content_by_lua"]:56: invalid escape sequence near
> '"^(https?', client: 184.108.40.206, server: , request: "GET
> /s.php?a=8081&u=http://ankitjain.in HTTP/1.1", host: "lb1"
It seems that you're running to double-escaping nightmare documented here:
The best practice is to use the content_by_lua_file directive instead
of content_by_lua and to put your Lua code into separate .lua files.
Using external .lua files also have the merit of bypassing the Lua
code cache during development, see
By turning off lua_code_cache during development, you can edit your
.lua files and they will take effect without reloading nginx, just
like php pages. But please keep in mind, it is for development only.
It's a *very* bad idea to turn off the lua code cache in production.
BTW, I'm cc'ing the openresty mailing list. So other people can see
our discussion here ;)