Reputation: 3
I want the space between the span tags to be replaced by
<span style="font-size:11;color:black"> </span>
I wrote this regex:
Regex.Replace(xml, @"<span[^>]*?>\s*</span>", (match) => match.Value.Replace(" ", " "), RegexOptions.IgnoreCase);
But it give me this output:
<span style="font-size:11;color:black"> </span>
It also places the
after the span.
Upvotes: 0
Views: 1506
Reputation: 2534
Use Regex.Replace
Regex regex = new Regex(@"<span([^>]*)>\s*</span>");
String output = regex.Replace(input, "<span$1> </span>");
Upvotes: 0
Reputation: 25573
You could use
@"(?<=<span[^>]*?>)\s*(?=</span>)"
as your regex.
Be aware, that parsing HTML with regular expressions is frowned upon and will break horribly when encountering (among others) HTML Comments and JavaScript.
Upvotes: 1