Re[2]: [PHP] preg_replace brain teaser

From: Date: Wed, 16 Apr 2003 08:47:20 +0000
Subject: Re[2]: [PHP] preg_replace brain teaser
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-144085@lists.php.net to get a copy of this message
Hi, Wednesday, April 16, 2003, 5:39:52 PM, you wrote: Ssd> Hello Ssd> Just realized that my intention to do it in just one pattern is pretty Ssd> stupid and won't work since I'm trying to replace two things at the same Ssd> time. The actuall match pattern and the escaped { so forget the question. Ssd> I'll just do it in two replaces. I'll also benchmark the different options Ssd> (callback, no callback) to see which one is really faster. >> You might want to try preg_replace_calback() as it is quite a bit Ssd> faster. Ssd> I can't believe that preg_replace_callback is actually faster since it has Ssd> the overhead of calling a function. I'll post my results. Ssd> That still leaves the first question to be answered.... any ideas? >> "(?<!\\)\{([a-zA-Z0-9_-]+?)\}" which >> results in an error: >> Warning: Compilation failed: lookbehind assertion is not fixed length at >> offset 31 in d:\eclipse_21\workspace\webframework\classes\I18N.class.php >> on line 320 >> First question (this is slightly off topic) I have is why is the >> lookbehind not a fixed length? It should only be one '\'. Ssd> Stefan Langer preg_replace_callback() will only be faster if you have more than one variable to replace otherwise preg_replace() will be a bit quicker. With multiple matches though preg_replace_callback() only needs to scan the string once to get all the changes. I don't know enough about regex to answer your first question. -- regards, Tom

« previous php.general (#144085) next »