Posted by Patrick Drouin on 12/17/07 16:03
Hello everyone,
I am puzzled at PHP's handling of regex. Here's the code:
<?php
$str="aabcc";
$pattern="/((a+)b?(c+))/";
preg_match_all($pattern,$str,$matches);
print_r($matches[0]);
?>
The behaviour I expect from the above would be to match:
a
aa
c
cc
abc
aabc
abcc
aabbcc
The output is ALWAYS the maximum strings :
Array
(
[0] => Array
(
[0] => aabcc
)
[1] => Array
(
[0] => aabcc
)
[2] => Array
(
[0] => aa
)
[3] => Array
(
[0] => cc
)
)
Any idea why the substrings are not picked up?
Thanks
Patrick
Navigation:
[Reply to this message]
|