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