You are here: Re: pattern match and extract problem « PHP Programming Language « IT news, forums, messages
Re: pattern match and extract problem

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация