简体   繁体   中英

How can I validate the range A-K without I, using a regex?

I need to validate a string which will have the format [char][char][num][num][char].

I need to find out if the [char] has anything between AK but not I.

Use a char class and add the two ranges:

[A-HJ-K]

JK is not really a range and adding the other requirements, try something like:

^[A-HJK]{2}\d{2}[A-HJK]$

See it here on Regexr .

^ is an anchor for the start of the string

$ is the anchor for the end of the string

Those anchors are important, otherwise you can match substrings.

[a-hj-k]{2}\d{2}[a-hj-k]

正则表达式可视化

Debuggex Demo

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