execAll

作者: Wrestle_Mania | 来源:发表于2021-05-26 10:34 被阅读0次
    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));

相关文章

网友评论

      本文标题:execAll

      本文链接:https://www.haomeiwen.com/subject/bifksltx.html