|
Posted by Jim Michaels on 02/17/06 10:30
"David Moore" <dave_m_moore@post2me.freeserve.co.uk> wrote in message
news:dsb232$ean$1@news7.svr.pol.co.uk...
> 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:
>
> 'The store had apples(20) and pears(30)'
>
> how do I extract the '20' and '30'? ie. if the pattern is 'apples(??)',
> how do I expect the '??'.
sounds like you only want the numbers. easy.
preg_match_all("/\((\d\d)\)/", $string, $matches);
or if you want to handle any number of digits,
preg_match_all("/\((\d+)\)/", $string, $matches);
>
>
> Ta in advance,
> Dave
>
>
Navigation:
[Reply to this message]
|