正则表达式匹配字母字符后跟 4 个字母数字 [英] regex matching alpha character followed by 4 alphanumerics
问题描述
我需要以下模式的正则表达式:
I need a regex for the following pattern:
总共 5 个字符(字母和数字,仅此而已).
Total of 5 characters (alpha and numeric, nothing else).
第一个字符必须是字母(仅限A
、B
或C
)
first character must be a letter (A
, B
, or C
only)
剩下的 4 个字符可以是数字或字母.
the remaining 4 characters can be number or letter.
澄清:第一个字母只能是A
、B
或C
.
Clarifcation: the first letter can only be A
, B
, or C
.
示例:
A1234
有效D1234
无效
A1234
is validD1234
is invalid
推荐答案
Grrr... 由于新的澄清"而编辑了正则表达式 :)
Grrr... edited regex due to new "clarification" :)
^[A-C][a-zA-Z0-9]{4}$
用英语解释上述正则表达式...
To explain the above Regex in English...
^
和 $
表示从头到尾"(这确保整个字符串必须完全匹配)
^
and $
mean "From start to finish" (this ensures that the whole string must perfectly match)
[A-C]
表示匹配 A
、B
或 C
"
[A-C]
means "Match either A
, B
, or C
"
[a-zA-Z0-9]{4}
表示匹配 4 个小写字母、大写字母或数字"
[a-zA-Z0-9]{4}
means "Match 4 lower case letters, upper case letters, or numbers"
这篇关于正则表达式匹配字母字符后跟 4 个字母数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!