简体   繁体   中英

regex match range but not certain characters

How do i write regex so it matches AZ but not characters b,h,i. Only way i could think of is by using custom ranges.

/[[A][C-G][J-Z]]/gi

This is what i can think of, i don't think this is correct regex, even. i'd like to not write custom ranges if possible. As it's complicate things a lot more.

What i'm trying to do is make characters increase by one so a becomes b, c -> d, z -> a. Except some words. And this is my strategy... find all words except them, run them through match string and replace them with character that is one ahead using charcode.

One way is to use negative lookahead:

/(?![BHI])[A-Z]/i

This will match anything in range [AZ] except characters B , H and I .

RegEx 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