I'm trying to use a RegEx that will catch any pre 1980's VIN (Vehicle Identification Numbers). Anythign pre 1980's will not be required to be 17 digits and can contain 'O's and 'U's.
This site claimed to have a RegEx for it (it also explains the VIN rules): http://lamptricks.blogspot.com/2012/03/vin-regex-pre-1980-and-new.html
Here's the RegEx: ^((([a-h,A-H,j-n,J-N,p-z,P-Z,0-9]{9})([a-h,A-H,j-n,J-N,p,P,r-t,R-T,v-z,V-Z,0-9])([a-h,A-H,j-n,J-N,p-z,P-Z,0-9])(\d{6}))|(([a-h,A-H,j-z,J-Z,0-9]{6,11})(\d{5})))$
But the following VIN did not pass the test: BCG23253
It ends and 5 digits and is 8 characters long-- which thie RegEx accounts for... Is this VIN just faulty or is the RegEx?
First of all, the regex you found needs some work. I think the author doesn't understand what commas mean inside character classes, for one thing. If you ignore the needless commas and the capture groups, you can simplify the whole thing to this:
...and then further, depending on your regex engine:
That being said, the number you gave (
BCG23253
) doesn't satisfy the requirement because it's only 8 characters long. To satisfy the bare minimum requirements (the[a-hj-z0-9]{6-11}\d{5}
part above), your input would have to be 11-17 characters long, end in 5 numbers, and not include the letterI
.So
BCG23253
shouldn't pass, butBCGBCG23253
(for example) would. As I said in my comment above, I think we need more information about the specific matches you're looking for. It sounds to me like the regex you've posted is made for matching post-1980 VINs, not pre-1980 VINs. Either that, orBCG23253
isn't a valid VIN after all.