Reputation: 628
I have to remove the span tags inside a string such:
<span>Operation Gambling:</span><span>la mano della crimitalità </span><span>sull'azzardo</span>
To do this, I use the following regexp:
Regex.Replace(inHTML, "<span[^>]*?>", string.Empty).Replace("</span>", " </span>");
the result sometimes is correct but in this case is:
Operazione Gambling: la mano della crimitalità sull azzardo
As you can see the single quote has been remove, how can I keep it by modifying the pattern?
Upvotes: 1
Views: 2833
Reputation: 10824
You can use this code for removing HTML tag inside your string:
var str = "<span>Operation Gambling:</span><span>la mano della crimitalità </span><span>sull'azzardo</span>";
String result = Regex.Replace(str, @"<[^>]*>", String.Empty);
System.Console.WriteLine(result);
Or this regex for removing just span tags:
Regex.Replace(str, @"</?span( [^>]*|/)?>", String.Empty);
Upvotes: 5