const str = "zhufeng2019yangfan2020qihang2021";
const reg = /\d+/;
(() => {
function execAll(str = "") {
let arr = [],
res = this.exec(str);
if (!this.global) return [res[0]];
while (res) {
arr.push(res[0]);
res = this.exec(str);
}
return arr;
}
RegExp.prototype.execAll = execAll;
})();
console.log(reg.execAll(str));
网友评论