I have a given string:
"Hi there <ss type="laugh">:)</ss>"
When I'm using
Regex.Replace(s, @"<(.|\n)*?>", string.Empty);
It returns me
"Hi there :)"
How can i modify the Expression to remove all "ss" tags and everything between them?
The string contains a regular XML tag, thus, you can make use of XElement.
This code will just keep the text of the outer element (text outside tags):
var s = "Hi there <ss type=\"laugh\">:)</ss>";
var el = XElement.Parse(string.Format("<root1>{0}</root1>", s));
var result = string.Concat(el.Nodes().OfType<XText>().Select(t => t.Value)).Trim();
Just make sure to use System.Xml.Linq namespace.
If you have other XML tags and you just want to remove ss tags:
var s = "<b>Hi</b> there <ss type=\"laugh\">:)</ss>";
var el = XElement.Parse(string.Format("<root1>{0}</root1>", s));
el.Descendants("ss").Remove();
var reader = el.CreateReader();
reader.MoveToContent();
var result2 = reader.ReadInnerXml().Trim();
@"<ss(.|\n)*?ss>"?