-3

I am working on validating UK driving license using regex. But the regex does not match accurately.

example, MORGA753116SM9IJ is a valid driving license and it matches but if I append some random characters like 123abc to it MORGA753116SM9IJ123abc, then it matches till '123abc' which is wrong.

see https://regex101.com/r/GwEJId/4

Jan
  • 42,290
  • 8
  • 54
  • 79
Amey P Naik
  • 710
  • 1
  • 8
  • 18

1 Answers1

1

Sandwich your regex between word boundary metacharacters \b:

\b[A-Z]{1,5}[9]{0,4}[0-9]{6}[A-Z]{1,2}[9]{0,1}[0-9][A-Z0-9]{2}\b

Demo

TeWu
  • 5,928
  • 2
  • 22
  • 36