You are here: Want regular expression to stop at first occurrence of word « PHP Programming Language « IT news, forums, messages
Want regular expression to stop at first occurrence of word

Posted by e_matthes on 02/26/07 06:13

Hello all,

Say I have the following string:

$string = "list of whales: white beluga whale humpback whale atlantic
humpback whale";

I want to pull out the first kind of whale (white beluga). I want
this to work regardless of whether the first whale is a white beluga,
or a humpback, etc. I tried:

$regExp = "/(whales:)(.*)(whale)/";
$outputArray = array();
if ( preg_match($regExp, $string, $outputArray) ) {
print "$outputArray[2]<br>";
}

But, the output is "white beluga whale humpback whale atlantic
humpback", as I expected. I know how to stop after finding a single
character, but I can't figure out how to stop after finding a single
instance of a word. Any help? Thanks.

 

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

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