|
Posted by Allen on 02/08/06 01:33
On Tue, 07 Feb 2006 16:05:32 -0500, David Moore
<dave_m_moore@post2me.freeserve.co.uk> wrote:
> Hi All,
> I expect someone can crack this one in no time.
>
> Ok, what I'd like to do is to match a pattern in a string and extract a
> portion of it. For example if I had a string like:
I prefer using the preg functions to extract parts of strings, but that
requires at least a basic understanding of regular expressions. At any
rate, if you want to capture all instances of word(number) you could do
this:
preg_match_all('/[a-z]+\(([0-9]+)\)/im',$string,$matches);
$matches[0] would be an array of apples(20), pears(30) etc.,
$matches[1] would be an array of all the numbers (20, 30, etc.)
regex match result -> http://tinyurl.com/9yrmc
A.
--
http://RReplace.com
A Web based regular expressions powered find/replace utility
Navigation:
[Reply to this message]
|