exec
带有全局正则表达式的表达式应在循环中使用,因为它仍将检索所有匹配的子表达式。所以:
var re = /[^\/]+/g;
var match;
while (match = re.exec('/a/b/c/d')) {
// match is Now the next match, in array form.
}
// No more matches.
String.match
为您执行此操作,并丢弃捕获的组。
RegExp的exec()函数和String的match()函数有什么区别?
exec
带有全局正则表达式的表达式应在循环中使用,因为它仍将检索所有匹配的子表达式。所以:
var re = /[^\/]+/g;
var match;
while (match = re.exec('/a/b/c/d')) {
// match is Now the next match, in array form.
}
// No more matches.
String.match
为您执行此操作,并丢弃捕获的组。