我有一个像这样的字符串:
Executed 29 of 31 (3 FAILED) (skipped 2) (0.283 secs / 0.08 secs)
我想获取
skipped
之后的值。但是如果我给正则表达式为:/skipped/
它仅与
skipped
字符匹配,但我想在此之后获取数字2
。如何在javascript中做到这一点?
最佳答案
skipped\s+(\d+)
尝试此操作。捕获捕获或分组。
参见演示。
https://www.regex101.com/r/rG7gX4/9
var re = /skipped\s+(\d+)/gmi;
var str = 'Executed 29 of 31 (3 FAILED) (skipped 2) (0.283 secs / 0.08 secs)';
var m;
while ((m = re.exec(str)) != null) {
if (m.index === re.lastIndex) {
re.lastIndex++;
}
// View your result using the m-variable.
// eg m[0] etc.
}
关于javascript - 获取字符后的数字值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28104142/