我有一个这样的字符串:
Executed 29 of 31 (3 FAILED) (skipped 2) (0.283 secs / 0.08 secs)
我希望获得skipped
之后的值。但如果我把正则表达式作为:
/skipped/
它只匹配skipped
字符,但我希望在此之后获得数字2
。
如何在javascript中执行此操作?
答案 0 :(得分:3)
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.
}