开发者

Javascript match: stop at second match on /g flag

开发者 https://www.devze.com 2023-03-24 14:15 出处:网络
Is it possible to sto开发者_StackOverflow中文版p at second match instead of letting iterate through whole string?

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

精彩评论

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

关注公众号