Reply to Re: regex question - can't get unclosed quote marks inside of HTML tags

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация