I am trying to remove the special characters of a string that will be included in a service but as I am using it removes certain tags, I have tried with a regular expression but I only need to validate the content that is inside the tags <> "here" </>
Regex estructureXml = new Regex(@"(?<initialTag>\<.+?\>)(?<content>.+?)(?<finalTag>\</.+?\>)", RegexOptions.Compiled);
Regex filter = new Regex(@"[^\w]", RegexOptions.Compiled);
string xmlClean = estructureXml.Replace(xmlTest, new MatchEvaluator(c =>
{
return $"{c.Groups["initialTag"].Value}{filter.Replace(c.Groups["content"].Value, string.Empty)}{c.Groups["finalTag"].Value}";
}));
this is the xml that I test in the string
<case-data process="123456">
<description>sadáwwwwwlsdasdas,.-#$%$&%& hoila fhd!°$%&</description>
<accounts>123-usser</accounts>
<parameters>
<parameter_process id="1298">123456,.-()/*--+!$%78</parameter_process>
<parameter_process id="1299">mail-//(&&(/@mail.com</parameter_process>
</parameters>
</case-data>
I also try with this but i thinks it is not the best way
strXml = Regex.Replace(strXml, @"([^</\w\s-="">@.])", "") ;