I'm wondering if someone can help me to create a regular expression to check if a string matches the new Medicare MBI number format. Here are the specifics in regards to character position and what they can contain.
I'm using Cache ObjectScript, but any language would be helpful just so I can get the idea.
If PCRE
is an option, you could leverage subroutines:
(?(DEFINE)
(?P<numeric>\d) # numbers
(?P<abc>(?![SLOIBZ])[A-Z]) # A-Z without S,L,O,I,B,Z
(?P<both>(?&numeric)|(?&abc)) # combined
)
^ # start of line/string
(?&numeric)(?&abc)(?&both) # in packs of three
(?&numeric)(?&abc)(?&both)
(?&numeric)(?&abc)(?&abc)
(?&numeric)(?&numeric)
$ # end of line/string
Paste your IDs into the demo on regex101.com (but don't save it on regex101 or you'll expose those IDs to the public permanently).
^
\d
(?![SLOIBZ])[A-Z]
\d|(?![SLOIBZ])[A-Z]
\d
(?![SLOIBZ])[A-Z]
\d|(?![SLOIBZ])[A-Z]
\d
(?![SLOIBZ])[A-Z]
(?![SLOIBZ])[A-Z]
\d
\d
$
Or condensed (just copy and paste it):
^\d(?![SLOIBZ])[A-Z]\d|(?![SLOIBZ])[A-Z]\d(?![SLOIBZ])[A-Z]\d|(?![SLOIBZ])[A-Z]\d(?![SLOIBZ])[A-Z](?![SLOIBZ])[A-Z]\d\d$
First position should be 1-9
https://www.cms.gov/Outreach-and-Education/Medicare-Learning-Network-MLN/MLNProducts/Downloads/MedicareCard-FactSheet-TextOnly-909365.pdf
\b[1-9][AC-HJKMNP-RT-Yac-hjkmnp-rt-y][AC-HJKMNP-RT-Yac-hjkmnp-rt-y0-9][0-9]-?[AC-HJKMNP-RT-Yac-hjkmnp-rt-y][AC-HJKMNP-RT-Yac-hjkmnp-rt-y0-9][0-9]-?[AC-HJKMNP-RT-Yac-hjkmnp-rt-y]{2}\d{2}\b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With