Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7936893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:21:14+00:00 2026-06-03T22:21:14+00:00

I have a string that may contain XML and normal string. I need to

  • 0

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>&#x2260;</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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:21:17+00:00Added an answer on June 3, 2026 at 10:21 pm

    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.

    string yourstring = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">   <mi>a</mi><mo>&#x2260;</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>";
    
    try
    {
         yourstring = Regex.Replace(yourstring, "(<math[^>]+>.+?</math>)", "");
    }
    catch (ArgumentException ex)
    {
         // Syntax error in the regular expression
    }
    

    The resulting string is:

    , that is mixed in with this other content 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array that contains string which may contain whitespaces appended to the
I have a string that may contain 0 or more urls. I want to
I have some html string that is coming from telerik radeditor, it may contain
We have a string field which can contain XML or plain text. The XML
I have a string for example, that may contain special characters ( + ,
I have a string that may contain numbers as well as upper and lower
I have a string that may contain substring: <h1 style=margin: 0; padding: 0 class=title_big>Item
I am currently working on a project where I have several string that may
I have a string array, and it may contain an element with the text
In my C# app, XML data may contain arbitrary element text that's already been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.