I'm using the following regexp with PHP's preg_replace:
$f[] = '/href\=\"([a-zA-Z\_]*?).php\?(.*?)\"/';
I want to update this to match all hyperlinks ending in .php with arguments (as it is now), but exclude any links that have the word "phpinfo" in the link..
I've tried:
$f[]='/href\=\"([a-zA-Z\_]*?).php\?(.*?!phpinfo)\"/';
But I fear I am doing it all wrong, it is not working - I have not been able to find a similar example that I am able to adapt to get this working.
Use a negative lookahead based regex.
$f[] = '/\bhref="([a-zA-Z\_]*?).php\?((?:(?!phpinfo|").)*)"/';
The trickier part is this (?:(?!phpinfo|").)*
which matches any character but not of double quotes or phpinfo
, zero or more times. What I mean by "not of phpinfo
" is, the following character would be any but not the starting letter in substring phpinfo
ie, p
. So this would match p
only if the following chars must not be hpinfo
.