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为您执行此操作,并丢弃捕获的组。

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为您执行此操作,并丢弃捕获的组。