RE: [PHP] ereg_replace - How do I stop it being "greedy"?

From: Date: Fri, 07 Sep 2001 16:35:24 +0000
Subject: RE: [PHP] ereg_replace - How do I stop it being "greedy"?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-66431@lists.php.net to get a copy of this message
look into the s modifier...it makes a dot match a newline as well, where normally it wouldn't.... jack -----Original Message----- From: George Whiffen [mailto:george@intellnet.net.uk] Sent: Friday, September 07, 2001 1:09 PM To: php-general@lists.php.net Subject: [PHP] ereg_replace - How do I stop it being "greedy"? Hi, I've got a problem with regular expression syntax with ereg_replace: ereg_replace(':start:(.*):end:','this is \\1',':start: first :end: middle :start: last :end:'); returns - this is first :end: middle :start: last but I want - this is first middle this is last The problem seems to be that ereg_replace is being greedy on the match and matching as much as it can instead of just finding the first match, handling that and then going on to the next match. I can get it to work with preg_replace i.e. preg_replace(':start:(.*?):end:','this \\1',':start first :end: middle :start: last :end:') returns - this is first middle this is last But my actual string is on multiple lines, and preg_replace doesn't seem to continue trying to match on the next line, whereas ereg_replace happily treats newlines just like any other character. So how do I stop ereg_replace being greedy or alternatively get preg_replace to treat multiple lines as a single source string? George -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#66431) next »