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 6114919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:01:54+00:00 2026-05-23T15:01:54+00:00

I’m using CodeMirror and trying to create my own version of the mode-changing demo

  • 0

I’m using CodeMirror and trying to create my own version of the mode-changing demo. I have a <textarea> on which I listen for changes and when there is a change, I want to look at the value in the <textarea> and determine if it is in the form of MathML.

So I just need to a very crude/hackish way to detect if the value in the <textarea> is MathML; it doesn’t have to be perfect. I’m thinking that I can run a regex when the <textarea> changes and look for any of the following tags:

<mfrac>
<msup>
<msub>
<msqrt>
<mroot>
<mfenced>
<msubsup>
<munderover>
<munder>
<mtable>
<mtr>
<mtd>
<mrow>
<mi>
<mo>

I need to take the string from the <textarea> and look if any of these tags are a substring. How would I write this regex?

  • 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-05-23T15:01:54+00:00Added an answer on May 23, 2026 at 3:01 pm
    /<m(?:frac|sup|sub|sqrt|root|fenced|subsup|underover|under|table|tr|td|row|i|o)\b/
    

    will identify the start of any such tag.

    To find a whole well-formed tag, you need to look for attributes before the closing > which is tougher. Something like

    /<m(?:frac|sup|sub|sqrt|root|fenced|subsup|underover|under|table|tr|td|row|i|o)\b[^>]*>/
    

    is not guaranteed to match a whole tag, but will make sure there is a > after the start of the tag.

    EDIT:

    … what is /]*>/?

    The regular expression has to be inside /.../ the same way a string has to be inside quotes because that is how the JavaScript interpreter tells a regular expression literal from a string or a number or any other kind of token.

    The <m matches the first two characters of any mathml tag. The (?: and ) form a non-capturing group. It’s the same as parentheses in an arithmetic expression. In the same way you have to use parentheses in (a + b) * (c + d) I use parentheses above to distinguish <m(?:frac|sup) from <mfrac|sup. The latter would match both "<mfrac" and "sup" without a <m before it.

    The \b at the end is a word break. It says that there shouldn’t be another word character after the name. So <msub\b matches "<msub" but not "<msubmarine".

    The [^>]* bit matches any number of characters other than '>'. The [...] is a character set, so [a-z] matches any lower-case roman letter. The ^ negates it, so [^a-z] matches any character that is not a lower-case roman letter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small

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.