0

apologies but am completely unaware of regex matching. therefore wanted to ask if someone can guide for creating a regex for following line (language C#)

$ ... $ <- anything that is within a $ .. $

and also for the following

$$ ... $$ <- anything that is within a $$ .. $$

the expressions may be as follows:

$ \[a\] + \[b\] + 23 $

to explain the requirement further, we are using MathJax and the input for mathjax is being taken from a rich textbox control (jqte).

but sometimes jqte injects its own html which does not render inside MathJax .

so the idea was to sanitize any input that is inside a MathJax expression and remove any HTML so that it can render properly.

Note: The [a] [b] etc are other variables that are assigned random values at runtime .

any help appreciated

Abdul Ali
  • 1,905
  • 8
  • 28
  • 50
  • `@"\$(.*?)\$"` or `@"\$\$(.*?)\$\$"` . Group index 1 contains the part you want. – Avinash Raj Jan 20 '15 at 10:44
  • 1
    Why are people posting answers in the comments section? – musefan Jan 20 '15 at 10:47
  • Note that `\begin{xyz}...\end{xyz}` also acts as delimiters, so you may need to handle them as well. The difficulty with all of these is that they can be nested. For example, `$x\in X\text {where $x\ne 1$}$` is perfectly legal, and it is difficult to get regular expressions to handle all the situations that MathJax will process. – Davide Cervone Jan 20 '15 at 22:58
  • Note that MathJax does not use regular expression matching of this kind to locate the math in the page. See the code linked to [this post](http://meta.math.stackexchange.com/questions/4208/a-prototype-for-incremental-preview-updates) for an example of how to locate the math within the page in a way that is compatible with MathJax. The code at the top of the user.js file does that searching (ignore most the rest of the code). – Davide Cervone Jan 20 '15 at 22:58
  • thank you for your suggestion. but currently the issue is to remove HTML inside the mathjax delimiters so that mathjax does not cause rendering issues. the required solution has been received (marked below) – Abdul Ali Jan 21 '15 at 10:43

1 Answers1

0

Which regex engine are you using?

I have found some working examples but you need to test them on your own:

\$(.*?)\$

Or for the second one

\$\$(.*?)\$\$

You can use both at the same time with the | Operator (Note that this will create three matches with one non-empty group each)

Reference

Community
  • 1
  • 1
Luca
  • 1,766
  • 3
  • 27
  • 38