I need to remove attributes from a string with tags.
Here is the C# code:
strContent = Regex.Replace(strContent, @"<(\w+)[^>]*(?<=( ?/?))>", "<$1$2>",
RegexOptions.IgnoreCase);
For example, this code will replace
This is some <div id="div1" class="cls1">content</div>. This is some more <span
id="span1" class="cls1">content</span>. This is <input type="readonly" id="input1"
value="further content"></input>.
with
This is some <div>content</div>. This is some more <span>content</span>. This is
<input></input>.
But I need a "whitelist" when removing the attributes. In the above example, I want that "input" tag attributes must not be removed. So I want the output as:
This is some <div>content</div>. This is some more <span>content</span>. This is
<input type="readonly" id="input1" value="further content"></input>.
Appreciate your help on this.