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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux