Regex pattern to match flight number and aircraft registration ID

Question:

My dataset has Flight number and aircraft reg of the form ‘xx-yyy’ i.e, two alphanumeric characters ‘xx’ followed by a hiphen ‘-‘ followed by 3 to 5 alphanumeric characters and I want to capture them using regex in python.

Examples:

1. pk-bkf
2. id-6236
3. ew-43950
4. 8q-iak
5. q2-274
6. pk-gjr
7. id-12345

I tried using this pattern: ^[a-z0-9]{2}[-][a-z0-9]{3, 5}$ but it doesn’t seem to match them.

Could someone help me write a pattern with this ‘hyphen’ inbetween?

Asked By: AnonymousMe

||

Answers:

^[a-z0-9]{2}[-][a-z0-9]{3,5}$

Seems to be working fine.

See demo.

https://regex101.com/r/RxbJx7/1

Answered By: vks
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.