I have a string that may contain XML and normal string. I need to parse out the <math....</math> for all instances in a string. How can I parse out multiple sections of this (from <math> to </math>) from this string?
Here is some content <math
xmlns="http://www.w3.org/1998/Math/MathML">
<mi>a</mi><mo>≠</mo><mn>0</mn> </math>, that is mixed in with
this other content <math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>a</mi><msup><mi>x</mi><mn>2</mn></msup> <mo>+</mo>
<mi>b</mi><mi>x</mi> <mo>+</mo> <mi>c</mi> <mo>=</mo> <mn>0</mn>
</math> we want to be able to seperate this string
Background:
I tried to make this question generic. The specifics of what I’m trying to do is for MVC3 encoding versus Raw. It will encode everything by default. I don’t want it to encode MathML, but do want it to encode everything else. So parts of it I want to render out as Html.Raw (the MathML part) and the rest I want to render as normally encoded strings.
I’m no regular expression boffin, but this is what I tried and I got back the correct result. Please use it as a base and modify it where necessary.
I got it from this post on Stackoverflow.
The resulting string is: