我想知道是否有人可以帮助我创建正则表达式来检查字符串是否与新的Medicare MBI数字格式匹配。以下是关于角色位置及其可以包含的内容的具体细节。
我使用的是Cache ObjectScript,但任何语言都会有所帮助,所以我可以理解。
答案 0 :(得分:5)
如果PCRE
是一个选项,您可以利用子程序:
(?(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
将您的ID粘贴到demo on regex101.com(但不要将其保存在regex101上,否则您将永久地将这些ID公开给公众)。
<小时/> 当然,它不是必须使用子程序,它只是使表达更清晰,更易读和可维护 但是,你很可能会去
^
\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
$
或浓缩(只需复制并粘贴):
^\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$
答案 1 :(得分:1)
第一个位置应为1-9
\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
答案 2 :(得分:0)
为先前的答案之一使用!
条件(负前瞻):
\b[1-9](?![sloibzSLOIBZ])[a-zA-Z](?![sloibzSLOIBZ)])[a-zA-Z0-9][0-9]-?(?![sloibzSLOIBZ])[a-zA-Z](?![sloibzSLOIBZ])[a-zA-Z0-9][0-9]-?(?![sloibzSLOIBZ])[a-zA-Z]{2}\d{2}\b
或更短:
\b[1-9](?![sloibzSLOIBZ])[a-zA-Z](?![sloibzSLOIBZ)])[a-zA-Z\d]\d-?(?![sloibzSLOIBZ])[a-zA-Z](?![sloibzSLOIBZ])[a-zA-Z\d]\d-?(?![sloibzSLOIBZ])[a-zA-Z]{2}\d{2}\b
答案 3 :(得分:-1)
public static boolean isValidHICN(String mHICN) {
String mPatternHICN = "[1-9]{1}[ACDEFGHJKMNPQRTUVWXY]{1}[A-N]{1}[0-9]{1}[ACDEFGHJKMNPQRTUVWXY]{1}[A-N]{1}[0-9]{1}[ACDEFGHJKMNPQRTUVWXY]{2}[0-9]{2}";
return (mHICN.matches(mPatternHICN));
}