没有更详细的信息:
var s = "<question>what is #(2,8) divided by #(3,4)</question>";
var t = s.replace(/(^|\s|>)#\((\d+),(\d+)\)($|\s|<)/g, "$1<span class='fraction'><span class='numerator'>$2</span><span class='denominator'>$3</span></span>$4");
现在是
"<question>what is <span class='fraction'><span class='numerator'>2</span><span class='denominator'>8</span></span> divided by <span class='fraction'><span class='numerator'>3</span><span class='denominator'>4</span></span></question>"
因此:正则表达式,您可以在其中找到 #(...,...) ,其中...
是数字,并且“函数”字符串被空格、句子的开头/结尾或尖括号包围。
但是,将其重写为 MathJax MathML 或 LaTeX 格式 ( http://mathjax.org ) 看起来会更好。