I want to write a regular expression on Google Form
First Character between 1 to 9 Second and Third any alphabets (Upper Case) and next 3 characters should be number like 541 or 001 but not 000
This expression is also taking 000
[1-9][A-Z]{2}[0-9]{3}
Use alternations:
[1-9][A-Z]{2}([1-9][0-9][0-9]|[0-9][1-9][0-9]|[0-9][0-9][1-9])
See regex demo
Here,
[1-9]
- matches 1 digit from1
to9
[A-Z]{2}
- two uppercase ASCII letters([1-9][0-9][0-9]|[0-9][1-9][0-9]|[0-9][0-9][1-9])
- 3 alternatives:[1-9][0-9][0-9]
- 3-digit numbers starting with1
[0-9][1-9][0-9]
- 3-digit numbers having1
in the middle[0-9][0-9][1-9]
- 3-digit numbers ending with1
Also, see this regex demo.
Use a negative look-ahead to avoid the triple zero at the end:
[1-9][A-Z]{2}(?!000)[0-9]{3}
Using the alternation operator [1-9][1-9][1-9]|0[1-9][1-9]|00[1-9]|0[1-9]0
来源:https://stackoverflow.com/questions/34697197/regular-expression-for-3-digit-without-000