Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

(02A1)[0-9A-Z]{14}(03)

My problem: It also matches this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

02A103EEFFFFF702A103

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

02A1(?:(?!03)[0-9A-Z]){14}03

If it cannot contain 02A1 either, use

02A1(?:(?!03|02A1)[0-9A-Z]){14}03

See this regex demo.

Details:

  • 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.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading