Re: greedy preg

From: Date: Wed, 06 Aug 2003 22:22:28 +0000
Subject: Re: greedy preg
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-158575@lists.php.net to get a copy of this message
skate wrote:
$contents = preg_replace( "|<item>.*?$file.*?</item>|si", "", $contents ); it's being run on an XML file, where each entry is <item>......</item> with a $file pointer in there. it works okay, except for the fact that it deletes that record, and every record before it. i can't figure out why it's being greedy? i know i gotta be missing something real simple...
What are the possible values of $file? Are you looking to replace just a specific occurance of a $file between <item> tags? Maybe this will help: $contents = preg_replace("|<item>[^<]*$file[^<]*</item>|si","",$contents); or just use the 'U' modifier for "ungreedy"... -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ PHP|Architect: A magazine for PHP Professionals – www.phparch.com

« previous php.general (#158575) next »