Re: [pcre-dev] Unmatched subpattern become wildcard

Top Page
Delete this message
Author: Tib
Date:  
To: pcre-dev
Subject: Re: [pcre-dev] Unmatched subpattern become wildcard
Hi,

Now I confirmed that this behavior starts from 8.13.
8.12 only matches "test".

Best regards,
Tiberius Teng

On Wed, Dec 21, 2011 at 3:10 PM, Tib <tiberius.teng@???> wrote:
> Hi,
>
> I just upgraded from PCRE 8.10 to PCRE 8.21, and surprisingly found
> the following behavior change:
>
> $t='hello world test';
> preg_match('/(another)?(\1?)test/', $t, $m);
> var_dump($m);
>
> on 8.10 I got:
>
> array(3) {
>  [0]=>
>  string(4) "test"
>  [1]=>
>  string(0) ""
>  [2]=>
>  string(0) ""
> }
>
> Which is fine, but on 8.21 I got:
>
> array(3) {
>  [0]=>
>  string(16) "hello world test"
>  [1]=>
>  string(0) ""
>  [2]=>
>  string(12) "hello world "
> }
>
> When (another)? didn't match, I would assume \1 also match an empty string,
> however (\1?) part captured "hello world ", is this a bug or I
> misunderstand the syntax?
>
> Best regards,
> Tiberius Teng