js 实现类似php preg_match_all 函数的函数封装

function matchAll (data, exp) {
    var regex = exp;
    var Regex = new RegExp(regex, 'mg');
    var Matches = data.match(Regex);
    matchesArray = new Array();
    for (var i in Matches) {
        ngRegex = new RegExp(regex);
        ngMatches = Matches[i].match(ngRegex);
        matchesArray.push(ngMatches);
    }
    return matchesArray;
}
//将所有的外连转换成内链跳转
var exp = /\d+/;
var output = matchAll('32323adsdsa32232adsds2332sdds', exp);
console.log(output);

posted @ 2022-06-24 00:20  盘思动  阅读(125)  评论(0编辑  收藏  举报