Regex to fix img tags
-
Hi there, I'm writing an XHTML site and i'm using FreeTextBox to do it, unfortunately is has a nasty habbit of breaking XHTML rules with upper case tags and removing closing slashes from image tags. Now i've written a function which fixes allot of HTML errors which it (or the user) may create. The functionalitu i'm missing is a regex which will turn
into
Can anyone supply a regex replace pattern which will do this? This is my function so far in case anyone else finds it useful. public static string MakeHTMLValid(string strInput) { strInput = Regex.Replace(strInput, "
", "
"); strInput = Regex.Replace(strInput, "
", "
"); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "
", "
"); strInput = Regex.Replace(strInput, "
", ""); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "
", "
"); strInput = Regex.Replace(strInput, "
", "
"); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "
", "
"); strInput = Regex.Replace(strInput, "
", "
"); strInput = Regex.Replace(strInput, "
", "
"); strInput = Regex.Replace(strInput, "
", "
"); strInput = Regex.Replace(strInput, "class=normalText", "class=\"normalText\"", RegexOptions.IgnoreCase); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "
", "
",RegexOptions.IgnoreCase);
-
Hi there, I'm writing an XHTML site and i'm using FreeTextBox to do it, unfortunately is has a nasty habbit of breaking XHTML rules with upper case tags and removing closing slashes from image tags. Now i've written a function which fixes allot of HTML errors which it (or the user) may create. The functionalitu i'm missing is a regex which will turn
into
Can anyone supply a regex replace pattern which will do this? This is my function so far in case anyone else finds it useful. public static string MakeHTMLValid(string strInput) { strInput = Regex.Replace(strInput, "
", "
"); strInput = Regex.Replace(strInput, "
", "
"); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "
", "
"); strInput = Regex.Replace(strInput, "
", ""); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "
", "
"); strInput = Regex.Replace(strInput, "
", "
"); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "
", "
"); strInput = Regex.Replace(strInput, "
", "
"); strInput = Regex.Replace(strInput, "
", "
"); strInput = Regex.Replace(strInput, "
", "
"); strInput = Regex.Replace(strInput, "class=normalText", "class=\"normalText\"", RegexOptions.IgnoreCase); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "
", "
",RegexOptions.IgnoreCase);
-
Parsing nested tags with regular expressions is not a trivial task, but for the tag it should work fine: string to find:
<img(?<content>[^>]+)>
string to replace:<img${content} />
regardsThanks for that it worked like a charm :)
"Gödel proved that any formal system that defines the primitive recursive functions must be either incomplete or inconsistent. In particular one could not prove from within the system that the system itself was consistent even though the question could be formulated within the system."