2014-09-22 86 views

回答

0

你可以使用这个表达式:

/(?:^|\}\$)(?:.(?!\$\{))*?(\d+)/ 

说明:

(?:  # a non-capturing group 
    ^|\}\$ # either the beginning of the string, or a "}$" 
)   # this will make sure we're not currently in a LaTeX thingy 

(?:  # another non-capturing group 
    .  # any character 
    (?!\$\{) # not followed by a "${" (make sure we don't go into a LaTeX thingy) 
)*?  # repeated zero or more times 

(\d+)  # the number that you want! 

我假设你的纬度eX将形成良好;即你将不会有像${ 123 }$ }$ 456 ${ 789 }$这样的带有不匹配括号的字符串。

试试:

var regex = /(?:^|\}\$)(?:.(?!\$\{))*?(\d+)/; 
 
var str = 'there is a LaTex is ${ \\frac{123}{456} }$ and a pure number 789 and another LaTex ${ 9^{n+1} }$'; 
 
alert(str.match(regex)[1]);

+0

也许数字是这样'“一把手101,还有一个乳胶$ {\\压裂{123} {456}} $和纯数字789和另一个LaTex $ {9^{n + 1}} $数字最后202“'。我想要匹配所有乳胶数字。 – nay 2014-09-22 06:21:54