Function to extract matching terms from a string
Posted: Thu Dec 03, 2009 8:19 pm
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.
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.