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].
精彩评论