Regex to Match a VIN
Copy the pattern, paste vehicle identification numbers, and see which fit the 17-character format. Below: why I, O and Q are banned.
What this pattern matches
It matches a Vehicle Identification Number: exactly 17 characters drawn from digits and letters, excluding I, O and Q.
Part by part
\b — word boundaries so a 17-char run inside a longer token is not falsely matched.
[A-HJ-NPR-Z0-9] — the allowed VIN character set: A–H, J–N, P, R–Z, and digits. This skips I, O, Q.
{17} — exactly seventeen of them.
Beyond the format
The ISO standard adds a check-digit in position 9. Format matching does not verify that; a full validator computes the checksum.
Use it in your code
import re
text = "1HGCM82633A004352, JH4KA9650MC000000, WVWZZZ1JZXW000001, SHORTVIN123"
pattern = r'''\b[A-HJ-NPR-Z0-9]{17}\b'''
for m in re.finditer(pattern, text):
print(m.group())
const text = "1HGCM82633A004352, JH4KA9650MC000000, WVWZZZ1JZXW000001, SHORTVIN123";
const re = new RegExp(String.raw`\b[A-HJ-NPR-Z0-9]{17}\b`, "g");
console.log(text.match(re));
FAQ
Why exclude I, O and Q?
They are banned from VINs because they look like 1, 0 and 0, avoiding transcription errors.
Should I match lower-case VINs?
VINs are upper-case. Uppercase the input or add the (i) flag if you accept lower-case entry.
Does this validate the check digit?
No. It only checks length and allowed characters. Position-9 checksum validation requires arithmetic beyond regex.