!--一个匹配字字符串是aabbcc或aaaabccc或者其他模式的运用-->
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<br data-filtered="filtered"><br data-filtered="filtered">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
}
|
|