简体   繁体   English

正则表达式以匹配由特定的3个字符串和9位数字组成的帐号

[英]Regular Expression to match account number consisting of specific 3 character string followed by 9 digits

I'm trying to craft a regular expression which will match an account number which consists of specific 3 characters strings followed by 9 digits. 我正在尝试制作一个正则表达式,该正则表达式将匹配一个由特定的3个字符串和9个数字组成的帐号。 eg 例如

abc123456789
xyz123456789
def987654321

I've figured out how to accomplish with the following expression but wanted to know if there was a better way: 我想出了如何用以下表达式完成操作,但想知道是否有更好的方法:

abc[0-9]{9}|xyz[0-9]{9}|def[0-9]{9}

您可以仅对特定的字符串进行“或”操作,因为这是唯一的更改:

(abc|xyz|def)[0-9]{9}

If the account number can only consist of abc , def or xyz , you can use | 如果帐号只能由abcdefxyz ,则可以使用| specifically for those strings, as pointed out by Jorge Campos: 如Jorge Campos所指出的,专门用于那些字符串:

(abc|def|xyz)\d{9}

However, assuming it can start with any combination of non-numerical characters, this is the most compact way to put it: 但是,假设它可以以非数字字符的任意组合开头,这是最紧凑的表示方式:

\D{3}\d{9}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM