![](https://img2018.cnblogs.com/blog/1853166/202001/1853166-20200126153019290-934193743.png) ![](https://img2018.cnblogs.com/blog/1853166/202001/18531... ...
export default (str, mode) => {
// 對模式變數進行正則篩選
let modeArr = mode.match(/([a-z.]\*)|([a-z]+(?=([a-z.]\*)|$))/g)
let cur = 0
let strLen = str.length
for (let i = 0, len = modeArr.length, m; i < len; i++) {
// 對於模式分為三類,.*|a*|cdef
m = modeArr[i].split('')
// 如果第二位是*表示是有模式的
if (m[1] === '*') {
if (m[0] === '.') {
cur = strLen
break
} else {
while (str[cur] === m[0]) {
cur++
}
}
} else {
for (let j = 0, jl = m.length; j < jl; j++) {
if (m[j] !== str[cur]) {
return false
} else {
cur++
}
}
}
}
return cur === strLen
}
let modeArr = mode.match(/([a-z.]\*)|([a-z]+(?=([a-z.]\*)|$))/g)