What's wrong with my regex
- by Tom Brown
Yes I know its usually a bad idea to parse HTML using RegEx, but that aside can someone explain the fault here:
string outputString = Regex.Replace(inputString, @"<?(?i:script|embed|object|frameset|frame|iframe|metalink|style|html|img|layer|ilayer|meta|applet)(.|\n)*?>", "");
if (outputString != inputString)
{
Console.WriteLine("unwanted tags detected");
}
It certainly detects the intended tags like: <script> and <html>, but it also rejects strings I want to allow such as
<B>Description</B>
and
<A href="http://www.mylink.com/index.html">A Link containing 'HTML'</A>