简体   繁体   中英

Regex to Match D or E followed by 2-3 digits

I've been looking for a regex to match a string that either starts with a D or an E followed 2 or 3 digits. I'm pretty terrible at writing regex but this is what I tried: ^[DE]{1}[0-9]{1,2}$

Thank you

starts with D or an E followed by 2 or 3 digits

You're close. Try this regex:

^[DE][0-9]{2,3}$

You don't need {1} as that is by default true and digits should be {2,3} instead of {1,2}

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