On Thu, May 17, 2012 at 4:06 AM, Sparsh Gupta <spars...@gmail.com> wrote:
> local abc = ngx.re.match("http://ankitjain.in","http(s?)\\:\\\/\\/ankitjain\\.in(\\/)?(\\?.*|#.*)?$","i")
> -- Does not match, abc is nil
BTW, this sample won't match because you have a syntax error in this
Lua code snippet. That is, you should get the following error in your
error.log when running the code above:
[error] ... invalid escape sequence near '\"http(s?)\:\'
That is, you're escaping "/" with "\" but "\/" is not a valid escaping
sequence in Lua at all (because "/" does not need to be escaped at
all). By fixing this issue, your example now matches on my side:
abc = ngx.re.match("http://ankitjain.in","http(s?)\\:\\/\\/ankitjain\\.in(\\/)?(\\?.*|#.*)?$","i")
BTW, you should use (?:...) instead of (...) in your regexes wherever
possible because the latter will introduce necessary subpattern
capturing which adds cost to the regex engine.
> local abc = ngx.re.match("http://ankitjain.in",row["regex"],"i") --
> Does not match, abc is nil
Why this one fails depends on the actual value of row["regex"] which I
cannot see from your mail. Please print its value out either with
ngx.say, or ngx.print, or ngx.log, or print.
The rule of thumb is: when in doubt, just print your regex string out
and see what it is.