子模式中的相同反向引用,php pcre regex [关闭]

I found this at

http://www.php.net/manual/en/regexp.reference.subpatterns.php

(?|(Sat)ur|(Sun))day

this mean (Sat) and Sun will be matched at same order

but When I test with regexbuddy it occurr a error abt syntax Thanks

This should work fine with a recent version of PCRE - did you make sure to switch regexbuddy into PCRE mode?

You'll need a pretty recent version too. My PHP 5.2.6 install is too old (PCRE 6.6 2006-02-06), while PHP 5.2.17 (8.02 2010-03-19) is fine.

This test PHP program:

$a = "it is Sunday tomorrow";
preg_match('/(?|(Sat)ur|(Sun))day/', $a, $m);
print_r($m);

Outputs this:

Array
(
    [0] => Sunday
    [1] => Sun
)

If your version of PCRE is too old, you'll get this error:

 Compilation failed: unrecognized character after (? at offset 2