I need a regular expression for the following conditions:
Examples:
Actually I have the following regex:
(?!PAK)([A-Z]{1,4}[A-Z0-9]{7})$
The problem with this regex is, that "ABCDE123" is a match.
How can I say, that the first 1 to 4 characters are only upper case chars and the remaining (until the total lenght of 8) are digits?
Remove the regex range operator and do an exact character length match. Add a positive lookahead at the very first to ensure that the length must be exactly 8.
^(?=.{8}$)(?!PAK)([A-Z]{1,4}[0-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.