Positional (numeric, match group) variables #43

Closed
tobia opened this Issue Jun 29, 2011 · 3 comments

Comments

Projects
None yet
3 participants

tobia commented Jun 29, 2011

Is there a way to access $1, $2 and such from lua?

I tried the obvious ngx.var[1] and ngx.var["1"] but they didn't work.

One workaround is to set them to other variables: set $arg1 $1; but it adds unnecessary clutter.

Contributor

PiotrSikora commented Jun 29, 2011

Did you try using named captures?

location ~ ^/directory/(?<filename>.*)$ {
    (...)
}
Owner

agentzh commented Jun 30, 2011

On Thu, Jun 30, 2011 at 5:03 AM, tobia
reply@reply.github.com
wrote:

Is there a way to access $1, $2 and such from lua?

I tried the obvious ngx.var[1] and ngx.var["1"] but they didn't work.

One workaround is to set them to other variables: set $arg1 $1; but it adds unnecessary clutter.

Yeah, this is a known issue. I'll attempt a fix today or so :)

Thanks for reminding me :)
-agentzh

@agentzh agentzh added a commit that referenced this issue Jul 4, 2011

@agentzh agentzh now we support ngx.var[1], ngx.var[2], and etc to refer to the nginx
regex capturing variables \$1, \$2, and etc in Lua. this resolved github
issue #43. thanks Tobia Conforto for reporting it.
7c835bd
Owner

agentzh commented Jul 4, 2011

On Thu, Jun 30, 2011 at 2:07 PM, agentzh agentzh@gmail.com wrote:

On Thu, Jun 30, 2011 at 5:03 AM, tobia
reply@reply.github.com
wrote:

Is there a way to access $1, $2 and such from lua?

I tried the obvious ngx.var[1] and ngx.var["1"] but they didn't work.

One workaround is to set them to other variables: set $arg1 $1; but it adds unnecessary clutter.

Yeah, this is a known issue. I'll attempt a fix today or so :)

I've fixed this in git master HEAD. Now ngx.var[1], ngx.var[2], etc
should work for $1, $2, and etc ;)

Enjoy!
-agentzh

agentzh closed this Jul 4, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment