开发者

Javascript match: stop at second match on /g flag

Is it possible to sto开发者_StackOverflow中文版p at second match instead of letting iterate through whole string?

Thanks ;)


Sure.

var exp = /.../g;
var matches = [
    exp.exec(str),
    exp.exec(str)
];

This matches the string two times. See exec [docs].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜