What could be the exact Regex.IsMatch expression for
span[class|align|style]
I tried with this one but i am not getting exact expected result
if (!Regex.IsMatch(n.Value, @"span\[.*?style.*?\]", RegexOptions.IgnoreCase))
n.Value = Regex.Replace(n.Value, @"(span\[.*?)(\])", "$1" + ValToAdd + "$2");
I am checking if the span contains ‘style’ element, if it is present then ‘style’ will not inserted with ‘span’ and vice-versa.
Any pointers?
You forgot to add
|before the ValToAdd.Also, your first regex would match
span[class|align|somestyle]. Use word boundary\bto match whole words. Note that this would still matchspan[class|align|some-style]as\bmatches before and after non-word characters. The following regex would match only thosestyles that are surrounded by[|or||or|].