note 14986 deleted from function.preg-match-all by sniper

From: Date: Tue, 30 Sep 2003 12:22:36 +0000
Subject: note 14986 deleted from function.preg-match-all by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57430@lists.php.net to get a copy of this message
Note Submitter: bdunogier@wanadoo.fr ---- Here is a sample that looks weird, even if it works: if (preg_match_all("/\"(.+?)\"/", $pattern, $patternMatches)) { echo ($count = (count($patternMatches[0])))." quote delimited strings:<br>"; for($i = 0; $i <= $count; $i++) { echo $patternMatches[0][$i]."<br>"; } } That code should extract all the strings between " and ", right ? And of course it does :) But... but $patternMatches[0] contains the matched strings including the ", which are out of the pattern in the preg match. That code ran on the string "this is" "a strange" "test" will output: 3 quote delimited strings: "this is" "a strange" "test" Replacing $patternMatches[0] with $patternMatches[1], we get what is expected: 3 quote delimited strings: this is a strange test Even if there is only one parenthesis pair like here.

« previous php.notes (#57430) next »