js正则的变量怎么用逻辑或连接起来?
let reg2 = /^([0-9])-([1-9])$/let reg3 = /^([0-9],)+[0-9]$/
let reg4 = /^[0-9]$/
let reg5 = reg2 | reg3 | reg4
let reg = new RegExp(`${reg5}`)
let score = '1,2'
console.log('eg.test(score)', reg.test(score));
if (reg.test(score) && score.replace(reg2, (_, $1,$2) => $1 < $2)) {
console.log('分数格式合规');
}
上面应该是合规才对的
回答:
错在这里
let reg5 = reg2 | reg3 | reg4
应该是
let reg5 = `${reg2}|${reg3}|${reg4}`
以上是 js正则的变量怎么用逻辑或连接起来? 的全部内容, 来源链接: utcz.com/p/933187.html