error in PHP Regular Expressions manual
| From: | Norm Olsen | Date: | Wed, 09 Jul 2008 20:59:44 +0000 |
| Subject: | error in PHP Regular Expressions manual | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-2061@lists.php.net to get a copy of this message | ||
I have been reading up on understanding regular expressions lately and have come across this link:
http://www.php.net/manual/en/regexp.reference.php
if you scroll down the subpatterns section, I come across this part:
For example, if the string "the red king" is matched against the pattern the ((red|white)
(king|queen)) the captured substrings are "red king", "red", and
"king", and are numbered 1, 2, and 3.
But when I try this by using the following code;
" . print_r($matches[0], 1) . "\n";
?>
Output:
Array
(
[0] => red king
)
I only get "red king" as a result. And this makes sense, as the pattern is looking for
either "red" or "white" followed by a blank space (personally, I would prefer to
see the '\s' but I digress), then followed by either "king" or
"queen". As such, there is no individual match for patterns like "red" or
"king" to be made using the pattern: ((red|white) (king|queen))
Cheers,
Norm
_________________________________________________________________