Hey guys,
I'm trying to write a regular expression that will insert a "/" character at the end of <img> tags that don't already have one, so the page will validate as xhtml. The closest I can get is this:
which adds a "/", even if there is one already there (making the doc invalid).
I'm pants with regex so if anyone can help that would be fantastic! By the way, the code is c#.
I'm trying to write a regular expression that will insert a "/" character at the end of <img> tags that don't already have one, so the page will validate as xhtml. The closest I can get is this:
Code:
html = Regex.Replace(html, @"<img([^>]+)>", "<img$1/>", RegexOptions.IgnoreCase);
which adds a "/", even if there is one already there (making the doc invalid).
I'm pants with regex so if anyone can help that would be fantastic! By the way, the code is c#.
