简体   繁体   中英

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. 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 | specifically for those strings, as pointed out by 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}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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