Posted by lawrence k on 12/06/05 08:28
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.
I see. So if I have a string like this:
<a href="myfile">myfile</a>
and I feed it to this function:
function command($string=false) {
$pattern = '/(.*)<a (.*)"(.*)>/i';
$replacement = '$1<$2"$3">';
$newString = preg_replace($pattern, $replacement,
$string);
return $newString;
}
I will get a match? But does that mean I'll end up with this:
<a href="myfile"">myfile</a>
With an extra quote mark? That is not the problem I was having.
But you are saying that I need to replace the final (.*) with something
that says "everything but a quote mark"?
[Back to original message]
|