Capturing a Repeated Group (explode | split)

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
lunarnet76
Forum Commoner
Posts: 67
Joined: Sun Apr 04, 2010 2:07 pm
Location: Edinburgh

Capturing a Repeated Group (explode | split)

Post by lunarnet76 »

hi folks!

I have a problem that is getting me crazy! :banghead:

I have

Code: Select all

$string='abcdefghijklmnopqrstuvwxyz';
preg_match('|(([a-z])*)|',$string,$matches);
and I want to have in $matches an array such as array('a','b','c','d'...) BUT preg_match keeps only the last match

I DO NOT WANT to use preg_match_all NOR explode, because this is just one small part of my regular expression

Is there a way to do it in php ? I have found the regular expression in http://www.regular-expressions.info/captureall.html
so it can work with other languages, but I don't know if you can do it with PHP!

Thanks!
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Capturing a Repeated Group (explode | split)

Post by McInfo »

lunarnet76 wrote:I have found the regular expression in http://www.regular-expressions.info/captureall.html
so it can work with other languages
I think you may have misunderstood that article.
regular-expressions.info wrote:!((abc|123)+)!. When this regex matches !abc123!, capturing group #1 will store abc123, and group #2 will store 123.
If you apply the same concept to your example, the pattern captures the entire string "abcdefghijklmnopqrstuvwxyz" in group #1 and "z" in group #2.

What is the larger pattern you are trying to match?
lunarnet76
Forum Commoner
Posts: 67
Joined: Sun Apr 04, 2010 2:07 pm
Location: Edinburgh

Re: Capturing a Repeated Group (explode | split)

Post by lunarnet76 »

oh gosh, I have read again the article to see what I did not understood, so apparently it simply not possible to get all the letters separated, you can have only the whole pack of letters...

I am doing an Object Query Language so I have something such as SELECT e.*,t.* FROM employee e JOIN telephone t

Then thanks a lot, now I am sure that it is simply not feasible^^ :D

Thank youuuuuu!
Post Reply