// 是否是正则数据 export const IS_ARRAY_STRING_REG = /\[[\S+,?]+\]/ /** * 将数组形式的字符串解构成真实数组,并不校验不需要的单引号,双引号等 * @param target 等待解构的字符串 */ export const deconstruct = target => { // 先去除空格,单引号,以及双引号 const targetWithoutSpace = target.replace(/\s/g, '').replace(/\'/g, '').replace(/\"/, '') // 如果当前是[target]这种形式,才参与解构 if (IS_ARRAY_STRING_REG.test(targetWithoutSpace)) { return targetWithoutSpace.match(/([\w|\-|\$|\&])+/g) } throw new Error('解构格式不正确,请检查') }