Friday, 13 September 2013

Need to remove white space between two tags with Regex

Need to remove white space between two tags with Regex

I have a bit of XML that I would like to strip the outer white space from.
As a preface: The output is not well formed xml, it's a propritary spec I
am relegated to dealing with.
The sample is:
<mattext>
<span>A</span>
<span>more text</span>
</mattext>
What I need is:
<mattext><span>A</span>
<span>more text</span></mattext>
Where all white space between the opening <mattext> and the first bit of
inner content is gone, and the same for the closing </mattext>.
I've tried:
var output = Regex.Replace(input, @"<mattext>*<", "<mattext>",
RegexOptions.Multiline);
But I'm not having any luck. Can anyone advise?
Thanks!

No comments:

Post a Comment