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

Regular Expression for this these characters : BASIC-GT-02-0078276

I need a regular expression for these characters. The first 5 characters "BASIC" is fixed for every string, followed by a "-", followed by next 2 characters which should be Alphabets, then 2 numbers and then 7 numbers.

I formed this one, but it not working.

^"BASIC"{5}[-]{1}[A-Z]{2}[-]{1}[0-9]{2}[-]{1}[0-9]{7}

some valid matches : BASIC-KH-67-8743532, BASIC-RF-00-2245890..

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

>Solution :

You may use:

^BASIC-[A-Z]{2}-[0-9]{2}-[0-9]{7}$

This pattern says to match:

  • ^ from the start of the string
  • BASIC match literal string "BASIC"
  • [A-Z]{2} match 2 uppercase letters
  • - hyphen
  • [0-9]{2} match 2 digits
  • - hyphen
  • [0-9]{7} match 7 digits
  • $ end of the 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