Page 1 of 1

multiple subpatterns matches

Posted: Tue Sep 14, 2010 9:21 am
by explodec14
Hi to all -
I have the string "apple banana lemon melon".
I have applied on it the following regex for matching:

Code: Select all

/apple banana| banana lemon|lemon melon/ims
I would like to accept at the end of the process 3 matches:
[*]apple banana
[*]banana lemon
[*]lemon melon

when i use preg_match_all/preg_match i get only the first subpattern that matches.

How can i get all of the 3 subpatterns ?

10x in advance

Re: multiple subpatterns matches

Posted: Tue Sep 14, 2010 8:25 pm
by ridgerunner
The preg_match_all function begins searching at the character position immediately following the previous match. Thus, any matches in your text which overlap after the first (the second two in your given example), will not be found.

You'll have to run each of the three subpatterns separately.