Jump to content

Help pcre subpattern


mengo

Recommended Posts

hello,you all.

 

there is a problem let me not understand.i have a few codes like this:

         $pattern = "/b©(d)\2efgh/";
         $subject = "abcddefghijk";
         preg_match_all($pattern, $subject, $matches);
         echo "<pre>";
         print_r($matches);
         echo "</pre>";

 

i want to use var $pattern capture str "bcddefgh" in var $subject with "\2" back reference,but the result is not what i want,it ouputs nothing but an empty array. i think i did nothing wrong, in php manual, it says a backslash followed by a non-0 number can represent a back reference.but why it fails?

 

is there something wrong with  my codes or an error in php manual? is there some other problems in php.ini or somewhere else?

 

help, thanks!!

 

 

Link to comment
https://forums.phpfreaks.com/topic/280064-help-pcre-subpattern/
Share on other sites

thank you for your help! I found another weird problem,for example:

$pattern = "/(1)(2)(3)(4)(5)(6)(7)((9)\3fgh/";
$subject = "1234567893fghijk";
preg_match_all($pattern, $subject, $matches);
echo "<pre>";
print_r($matches);
echo "</pre>";
echo chr(2);

form \1 to \7, no matter whick back reference is used, there will always get not correct result! But when changed to \8 or \9, if there is a respondding matching substring in variable $subject,while it will get correct result. Where there is a difference between these two conditions?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.