I have a regular expression like this (much simplified):
^(ab)*$
And am matching against this:
abababababababab
When I run it through preg_match
:
preg_match('/$(ab)*$/', 'abababababababab', $matches);
print_r($matches);
I get this:
Array
(
[0] => abababababababab
[1] => ab
)
Wheras I expect this:
Array
(
[0] => abababababababab
[1] => ab
[2] => ab
[3] => ab
[4] => ab
[5] => ab
[6] => ab
[7] => ab
[8] => ab
}
How can I get what I expect?
(Note that the subexpression could be more complicated, e.g. ([aA][bB])
, and I want the matched expressions in their order in the subject.)