Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regexps: How to return multiple matches

Status
Not open for further replies.

Mike Lewis

Programmer
Jan 10, 2003
17,516
Scotland
I am using a regular expression to return a substring .... something like this:

Code:
$source = ' blah blah blah [b]Fruit=Apple;[/b] blah
 blah [b]Fruit=Orange;[/b] blah blah [b]Fruit=Tangerine[/b]; blah ';

$pattern = 'Fruit=[A-Za-z]*;';
eregi($pattern, $source, $fruit);
echo $fruit[0];

(The bold text in the above code is just so that you can easily see the items I want to find.)

The above code correctly returns the first of the fruit. My question is: How do I retrieve the subsequent occurrences? Is there an easy way to do that using regexps?

Thanks in advance.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Feherke,

That looks like it's exactly what I want. Many thanks.

I haven't used the preg_ functions before. Maybe I should I should go with them from now on (unless there are any disadvantages?).

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
As of php 6 the preg library will be preloaded at runtime. so i see less and less disadvantage in using regex.

coupled with that, i've always thought that the effort of coding around a problem of minor system performance issue was never worth the equivalent cost of shoving another linux box in the mix! at least with interpreted languages.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top