pythonregexpii

Regex to identify a Medical Beneficiary Identifier(MBI) in python


So I am trying to create a regex for MBIs (medical beneficiary identifiers) in python and my regexes wont work.

Any example of a MBi is: 1EG4-TE5-MK73

Here is the format to MBIs:

I have tried using the following regex but to no avail:

mbi=re.compile(r"[1-9]{1}[^SLOIBZsloibz|^0-9]{1}[^SLOIBZsloibz]{1}[0-9]{1}-?[^SLOIBZsloibz|^0-9]{1}[^SLOIBZsloibz]{1}[0-9]{1}-?[^SLOIBZsloibz|^0-9]{1}[^SLOIBZsloibz|^0-9]{1}[0-9]{1}[0-9]{1}")

Any suggestions?!?!


Solution

  • Here is the format to MBIs:

    1. 11-Characters
    2. The MBI’s 2nd, 5th, 8th, and 9th characters will always be a letter.
    3. Characters 1, 4, 7, 10, and 11 will always be a number.

    There's no mention about the 3rd and 6th characters, but based on your example, you can use a regex like:

    \b\d[A-Z]{2}\d-[A-Z]{2}\d-[A-Z]{2}\d{2}\b
    

    Regex Demo


    Regex Explanation: enter image description here