e_matthes@hotmail.com wrote:
Quote:
$string = "list of whales: white beluga whale humpback whale atlantic
humpback whale";
Quote:
$regExp = "/(whales:)(.*)(whale)/";
if ( preg_match($regExp, $string, $outputArray) ) {
Quote:
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.
RegEx are greedy. That means RegEx match as much as they can. This means
your Expression stops with the last whale. To make it stop with the
first whale make your Expression ungreedey:
$regExp = "/(whales:)(.*?)(whale)/";
or
$regExp = "/(whales:)(.*)(whale)/U";
see:
http://en.wikipedia.org/wiki/Regular...dy_expressions
Heiko
--
http://portal.richler.de/ Namensportal zu Richler
http://www.richler.de/ Heiko Richler: Computer - Know How!
http://www.richler.info/ private Homepage