Regex to match LEGAL UK Number Plate [closed]

只谈情不闲聊 提交于 2020-01-30 13:25:07

问题


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 ...");
}

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 ?


回答1:


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.




回答2:


Angular ng-pattern:

ng-pattern="/\b[a-z]{2}([1-9]|0[2-9]|6[0-9]|1[0-9])[a-z]{3}|[A-HJ-NP-Y]\d{1,3}[A-Z]{3}|[A-Z]{3}\d{1,3}[A-HJ-NP-Y]|(?:[A-Z]{1,2}\d{1,4}|[A-Z]{3}\d{1,3})|(?:\d{1,4}[A-Z]{1,2}|\d{1,3}[A-Z]{3})\b/i"


来源:https://stackoverflow.com/questions/6215914/regex-to-match-legal-uk-number-plate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!