You are here: Regex help « PHP Programming Language « IT news, forums, messages
Regex help

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация