RegEx Match between beginning and ending problem


I want to match everything between "02A1" and "03" IF its 14 characters in between those two.

My RegEx Pattern looks like this:


My problem: It also matches this:


What am i doing wrong? "EEFFFFF7" is clearly not between 02A1 und 03 as before the EEFFFFF7 theres a 03 and after it theres a 02A1.

Can someone help me?

>Solution :

If the fourteen alphanumeric chars cannot contain a 03 substring, use


If it cannot contain 02A1 either, use


See this regex demo.


  • 02A1 – a 02A1 string
  • (?:(?!03|02A1)[0-9A-Z]){14} – fourteen occurrences of an uppercase ASCII letter or digit that does not start a 03 or 02A1 char sequence
  • 03 – a 03 string.

Leave a Reply Cancel reply