我正在寻找与文本'PDR'或'pdr'完全匹配的正则表达式和8位数,所以总共11位数,(3文本+8位数)
pdr16120008 - TRUE
PDR16120009 -TRUE
rdp16120001-错误
答案 0 :(得分:0)
^(pdr|PDR)\d{8}$
^ asserts position at start of a line
1st Capturing Group (pdr|PDR)
1st Alternative pdr
pdr matches the characters pdr literally (case sensitive)
2nd Alternative PDR
PDR matches the characters PDR literally (case sensitive)
\d{8} matches a digit (equal to [0-9])
{8} Quantifier — Matches exactly 8 times
$ asserts position at the end of a line
答案 1 :(得分:0)
正则表达并不难:
pdr
锚^
digits
i
修饰符以匹配不区分大小写。
const REGEX = /^pdr[0-9]{8}$/i;
let valids = ['pdr16120008', 'PDR16120009', 'rdp16120001']
.filter(input => REGEX.test(input))
;
console.log({valids});