Re: Negative Look Ahead Regex - Code Mistake or Bug?

From: Date: Mon, 18 Aug 2008 07:27:06 +0000
Subject: Re: Negative Look Ahead Regex - Code Mistake or Bug?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-278264@lists.php.net to get a copy of this message
Cameron B. Prince a écrit :
An example of the code is here: $buffer = preg_replace('/"http\:\/\/www\.domain\.com([\/\w\.-]*)(?!\?PHPSESSID\=2u0cca ffoh6jaeapkke35qpp87;?)/', '"http://www.domain.com$1?PHPSESSID=t9gksvpdcuobsnqt98qloe6lg4;', $buffer);
I never build my regex inline. I write them by pieces I can test. It is obviously to divide (and I don't know in english the end). So when the starting and ending marks are too frequents in my pattern, I use an other mark (like `). $domain = '(http://www\.domain\.com)' ; $path = '(/\\w*)+' ; $search_part = 'PHPSESSID=(?:[\w\d]+)' ; $re = sprintf("%s%s?%s", $domain, $path, $search_part) ; $buffer = '\1\2?PHPSESSID=t9gksvpdcuobsnqt98qloe6lg4;' ; $buffer = preg_match($re, $url, $buffer) ; So said, it doesn't work anymore when you'll have other parameters in your search part. -- Mickaël Wolff aka Lupus Michaelis http://lupusmic.org

« previous php.general (#278264) next »