Posted by lawrence k on 12/06/05 08:31
dennis.alund@gmail.com wrote:
> This isn't really a solution to your problem... just a hint of what's
> wrong; a quote is also a character... i.e. in the expression (.*) will
> also match a quote.
> What you want to look into is negative lookarounds; (?<!x)y matches an
> 'y' not preceeded by a 'x' and x(?!y) matches a 'x' not followed by an
> 'y'.
> But if you're not a regexp-ninja I'd recommend you to find an easier
> solution... negative lookarounds aint trivial.
So I want this?
function command($string=false) {
$pattern = '/(.*)<a (.*)"[^"]+>/i';
$replacement = '$1<a $2"$3">';
$newString = preg_replace($pattern, $replacement, $string);
return $newString;
return $string;
}
Navigation:
[Reply to this message]
|