|
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]
|