Javascript的正面LookBehind

时间:2018-03-03 01:07:19

标签: javascript regex

可以在这里使用一些帮助。由于我必须通过的特殊字符,我已经挖掘并找不到字符串。

尝试捕获“258”是以下字符串的任何数字: “ .value),258,'0')

以下是我要找的内容,因为我想要捕获的字符串可以是多位数字,只有数字0-9。

(?<=value\), )(.*)(?=\,)

任何替代方案都会有所帮助,因为不再支持Javascript的正面LookBehind :(

2 个答案:

答案 0 :(得分:1)

您可以使用捕获组,然后提取其中包含258的那个:

&#13;
&#13;
let regex = /(value\), )(\d*)/;
let string = ".value), 258, '0')";
let output = regex.exec(string);
console.log(output[2])

//output[0] is the whole match
//output[1] is the first capture group: "value), "
//output[2] is the second capture group: "258"
&#13;
&#13;
&#13;

答案 1 :(得分:0)

&#13;
&#13;
str = ".value), 258, '0')"
match = /value\), (\d+),/.exec(str)

if (match) console.log(match[1]);
&#13;
&#13;
&#13;