Re: Help with simple regular expression

From: Date: Mon, 25 Jun 2001 22:01:38 +0000
Subject: Re: Help with simple regular expression
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-55162@lists.php.net to get a copy of this message
In article <KFEKLFMNHDILCMFAEKJCOEJECLAA.scott@graphictype.com>, scott@graphictype.com ("scott [gts]") wrote: > preg_match('/<blah(.*?)>/', $text, $matches) > > in the case of perl regexp's, you have to specifically > tell the regexp not to be greedy. the "?" regexp modifier > is how you do this. (otherwise, the regexp will try and > match the maximum amount of text that it can, which > usually isnt what you want, since it'll match *eveything* > between "blah" and the last occurance of ">" in the text) More ways to achieve the same effect, using the "U" modifier to invert the greediness of a regex expression or sub-expression: preg_match('/<blah(.*)>/U', $text, $matches) preg_match('/<blah(.*?U)>/', $text, $matches) -- CC

« previous php.general (#55162) next »