ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2022-06-24 00:32:50  阅读:7  来源: 互联网

标签:regex 函数 matchesArray Matches preg js exp var new


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);

标签:regex,函数,matchesArray,Matches,preg,js,exp,var,new
来源: https://www.cnblogs.com/pansidong/p/16407294.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有