Page 1 of 1

Function to extract matching terms from a string

Posted: Thu Dec 03, 2009 8:19 pm
by Randwulf
Is there a function to extract matching terms (terms that match a regex pattern) from a string and into an array?

For example, if I had a string that said "aba.....bbb......ccc.....bba.....ada" and I had the regex pattern "/a[a-z]a/", I would want to get an array with two entries, "aba" and "ada". I searched for such a function in the API but couldn't find one. Is there any sort of function that will provide this sort of functionality? It would make my life a whole lot easier, although I can do what needs to be done with a lot of replace()s and explode()s.

Re: Function to extract matching terms from a string

Posted: Thu Dec 03, 2009 8:24 pm
by John Cartwright

Code: Select all

preg_match_all()

Re: Function to extract matching terms from a string

Posted: Thu Dec 03, 2009 8:27 pm
by Randwulf
Ahhh, yes. Silly me, I didn't think before to check the parameter list for extra return values.

Thanks