Forum: NGINX PCRE named captures sill counted in numerical variables list

1266aa99d1601b47bbd3ec22affbb81c?d=identicon&s=25 B.R. (Guest)
on 2014-04-03 15:09
(Received via mailing list)
I tried to configure the following location with something like:

location ~*
"^/([[:alpha:]]{1,8}(?<subtag>-[[:alpha:]]{1,8})?)(/.*[^/])?/?$" {
        try_files $uri $uri/  $2/?lang=$1&$args;
}

​However, the $2 variable does not catch the last part of the URI as
expected (either it catches the named capture or nothing at all, that I
do
not know nor care).​

​Using $3 instead of $2 does the job.​


​I thought that using named captures allowed for those capture not to be
counted in numerical variable​
​.

​
​Am I wrong expecting that?
---
*B. R.*
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2014-04-03 15:22
(Received via mailing list)
Hello!

On Thu, Apr 03, 2014 at 03:08:14PM +0200, B.R. wrote:

>
> ​Using $3 instead of $2 does the job.​
>
>
> ​I thought that using named captures allowed for those capture not to be
> counted in numerical variable​
> ​.
>
> ​
> ​Am I wrong expecting that?

Yes, you are wrong, "man perlre" says:

       Named groups count in absolute and relative
       numbering, and so can also be referred to by those numbers.

The same does "man pcrepattern":

       Named  capturing parentheses are still allocated numbers
       as well as names, exactly as if the names were not  present.

From pattern point of view, it's just an human-friendly alias for
a capture.

--
Maxim Dounin
http://nginx.org/
1266aa99d1601b47bbd3ec22affbb81c?d=identicon&s=25 B.R. (Guest)
on 2014-04-03 15:44
(Received via mailing list)
​Thanks Maxim,

I just understood my mistake: I was confusing (once again, I think)
named
captures and subpatterns...

What I wanted to use was the OR logic capability of captures while
actually
not capturing them...
The starting question mark of both syntax confused me...

If anyone is intereted in it, the intended (and working) syntax is:
location ~* "^/([[:alpha:]]{1,8}(?:-[[:alpha:]]{1,8})?)(/.*[^/])?/?$" {
        try_files $uri $uri/  $2/?lang=$1&$args;
}

Working on multi-language URIs on webserver-side... ;o)
---
*B. R.*
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.