[英]Regex first three characters, then only numbers or characters, optionally followed by two digits
I am trying to create a regex that will match first three characters at the beginning, then digits or characters followed by (optionally) one character followed by two digits.我正在尝试创建一个正则表达式,它将在开头匹配前三个字符,然后是数字或字符,后跟(可选)一个字符,后跟两个数字。 The maximum length is 25.
最大长度为 25。
BER12345 - match
BER123456A10 - match
My attempt: ^(?=[AZ]{3,25}$)[A-Z0-9]{5,20}[0-9]{0,2]$
我的尝试:
^(?=[AZ]{3,25}$)[A-Z0-9]{5,20}[0-9]{0,2]$
This should do the trick:这应该可以解决问题:
(^[AZ]{3}[A-Z0-9]{1,19}[A-Z0-9]\d{2}$)|(^[AZ]{3}[A-Z0-9]{1,22}$)
Regex101 (^[AZ]{3}[A-Z0-9]{1,19}[A-Z0-9]\d{2}$)|(^[AZ]{3}[A-Z0-9]{1,22}$)
正则表达式101
BER - no match (desn't have digits or chars after begining)
BER456 - match
BER12345 - match
BER123456A10 - match
BER12345678910dasdd123 - no match (lowercase)
BER1234567890123456789123 - match (only numbers)
BER1234S67890AFF456789123 - match (uppercase)
BER1234S67890AFF4567891DA - match (with letters at the end)
BER12345678989A10dasdd123 - no match (lowercase)
BER1234S67890AFF456789123A - no match (max size)
BER1234567890123456789A10AAA123 - no match (max size)
If you want to match the first example above with only 3 chars BER
, just change {1,19}
and {1,22}
to {0,19}
and {0,22}
如果您想仅使用 3 个字符
BER
匹配上面的第一个示例,只需将{1,19}
和{1,22}
更改为 {0,19} 和 { {0,19}
{0,22}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.