Regular expression for A123ABC
regex
Solution
Your letter part is fine, below is just the numbers portion:
regex = "(?:2[1-9]|[3-9][0-9]|[1-8][0-9][0-9]|9[0-8][0-9]|99[0-8])"
`(?:...)` group, but do not capture. `2[1-9]` covers 21-29 `[3-9][0-9]` covers 30-99 `[1-8][0-9][0-9]` covers 100-899 `9[0-8][0-9]` covers 900-989 `99[0-8]` covers 990-998 `|` stands for "or"
Note: `[0-9]` may be replaced by `\d`. So, a more concise representation would be:
regex = "(?:2\d|[3-9]\d|[1-8]\d{2}|9[0-8]\d|99[0-8])"
Problem
I have a string in the format `A123ABC` - First letter cannot contain `<I,O,Q,U,Z>` - Next 3 digits (0-9) from 21-998 - Last 3 letters cannot include `<I,Q,Z>` I used the following expression `[A-HJ-NPR-TV-Y]{1}[0-9]{2,3}[A-HJ-PR-Y]{3}` But I am not able to restrict the number in the range 21-998.