一个匹配字字符串是aabbcc或者其他模式的运用
程序员文章站
2024-01-01 19:56:58
function isPattern(str, pattern) { let str_a = str.split(" "); let p_a = pattern.split(""); let noCpy = funct ......
<!--一个匹配字字符串是aabbcc或aaaabccc或者其他模式的运用-->
function ispattern(str, pattern) { let str_a = str.split(" "); let p_a = pattern.split(""); let nocpy = function (arr) { let temp = []; arr.foreach(element => { if (!temp.length || temp.indexof(element) < 0) { temp.push(element) } }); return temp }; let str_a_nocpy = nocpy(str_a); let p_a_nocpy = nocpy(p_a); str_a_nocpy.foreach((e, index) => { str = str.replace(new regexp(e, "gm"), p_a_nocpy[index]) }) str = str.replace(/\s*/gm, "") return str == pattern }