正则表达式匹配英国法律车牌 [英] Regex to match LEGAL UK Number Plate
问题描述
我一直在努力将合法的英国车牌号与以下正则表达式匹配,但这仅匹配新的车牌号,例如JS07 ZAS,而不是旧的J62 LNX格式,我需要一个表达式来匹配两者,我无法解决以匹配两种类型的板块.
i have been working on matching a legal uk number plate with the following regex expression , however this only matches new number plates like JS07 ZAS not the old J62 LNX format, i need a expression to match both and i cant work out how to match both type of plates.
var plateregex = "([A-HJ-PR-Y]{2}([0][1-9]|[1-9][0-9])|[A-HJ-PR-Y]{1}([1-9]|[1-2][0-9]|30|31|33|40|44|55|50|60|66|70|77|80|88|90|99|111|121|123|222|321|333|444|555|666|777|888|999|100|200|300|400|500|600|700|800|900))[ ][A-HJ-PR-Z]{3}$";
if (!platetext.match(plateregex)) {
var answer = window.confirm ("Non LEGAL Plate Detected ...");
}
好吧,这是我制作的正则表达式,可以匹配两种类型的板子^([A-HJ-PR-Y]{2,2}[056][0-9]\s?[A-HJ-PR-Y]{3,3})$|^([A-HJ-NP-Y]{1,3}[0-9]{2,3}?\s[A-Z]{3,3})$|^([A-Z]{1,3}\s?[0-9]{1,4}([A-Z]{1,1})?)$|^([0-9]{4,4}[A-Z]{1,3})$|^([A-Z]{1,2}\s?[0-9]{1,4})$|^([A-Z]{2,3}\s?[0-9]{1,4})$|^([0-9]{1,4}\s?[A-Z]{2,3})$
,但是此剂量匹配任何东西吗?什么时候应该做,您能在这里看到与javascript正则表达式一起使用时遇到的任何问题吗?
well here is the regex expression i made to match both type of plates ^([A-HJ-PR-Y]{2,2}[056][0-9]\s?[A-HJ-PR-Y]{3,3})$|^([A-HJ-NP-Y]{1,3}[0-9]{2,3}?\s[A-Z]{3,3})$|^([A-Z]{1,3}\s?[0-9]{1,4}([A-Z]{1,1})?)$|^([0-9]{4,4}[A-Z]{1,3})$|^([A-Z]{1,2}\s?[0-9]{1,4})$|^([A-Z]{2,3}\s?[0-9]{1,4})$|^([0-9]{1,4}\s?[A-Z]{2,3})$
however this dosent match anything ? when it should do can you see any problems here for using with javascript regex ?
推荐答案
一个快速的Google给了我这些
A quick Google gave me these
/\b[a-z]{2}([1-9]|0[2-9]|6[0-9]|1[0-9])[a-z]{3}\b/i # current series
/\b[A-HJ-NP-Y]\d{1,3}[A-Z]{3}\b/ # previous series
/\b[A-Z]{3}\d{1,3}[A-HJ-NP-Y]\b/ # previous series
/\b(?:[A-Z]{1,2}\d{1,4}|[A-Z]{3}\d{1,3})\b/ # old series - letters first
/\b(?:\d{1,4}[A-Z]{1,2}|\d{1,3}[A-Z]{3})\b/ # old series - digits first
看起来您必须分别进行测试.
Looks like you'll have to test them individually.
这篇关于正则表达式匹配英国法律车牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!