-1

Remove anchor tag with ID attribute by regex from an HTML string

Example .

<div>
    <p>
        Test code
    </p>
    <a id =some value></a>
    <a href=URL ></a>
</div>

Have to remove anchor tag with ID attribute. Output should be :

<div>
    <p>
        Test code
    </p>
    <a href=URL ></a>
</div>
Mohit S
  • 13,723
  • 6
  • 34
  • 69
Sanjeevi Subramani
  • 501
  • 1
  • 5
  • 16
  • You should show your efforts by showing what have you tried so far with what was the output vs expected output. Will increase the chances to get the answers – Mohit S Aug 23 '16 at 01:47

1 Answers1

1

You could try using HtmlAgilityPack for this instead of using Regex.

HtmlAgilityPack.HtmlDocument htmldoc = new HtmlAgilityPack.HtmlDocument();
var Anchors = htmldoc.DocumentNode.SelectNodes("//a");
foreach (var tag in Anchors)
{
    if(tag.Attributes["id"] != null) 
    {
        tag.Remove();
    }
}
Mohit S
  • 13,723
  • 6
  • 34
  • 69