0
正則表達式匹配號碼,我有這樣的"there is a LaTex is ${ \\frac{123}{456} }$ and a pure number 789 and another LaTex ${ 9^{n+1} }$"
我需要一個正則表達式來獲取數聲明,我不需要位於LaTeX的數字正則表達式匹配號碼出來的乳膠出來的乳膠
正則表達式匹配號碼,我有這樣的"there is a LaTex is ${ \\frac{123}{456} }$ and a pure number 789 and another LaTex ${ 9^{n+1} }$"
我需要一個正則表達式來獲取數聲明,我不需要位於LaTeX的數字正則表達式匹配號碼出來的乳膠出來的乳膠
你可以使用這個表達式:
/(?:^|\}\$)(?:.(?!\$\{))*?(\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]);
也許數字是這樣'「一把手101,還有一個乳膠$ {\\壓裂{123} {456}} $和純數字789和另一個LaTex $ {9^{n + 1}} $數字最後202「'。我想要匹配所有乳膠數字。 – nay 2014-09-22 06:21:54