65.9k views
4 votes
What is a regular expression that would match any digit 1-999?

User FredericK
by
7.2k points

1 Answer

1 vote

Answer:

[1-9][0-9]{0,2}

Step-by-step explanation:

The numbers to be matched consist of three digits with the following requirements:

- Digit 1 can take the values 1-9

- Digit 2 can take the values 0-9

- Digit 3 can take the values 0-9

- Digits 2 and 3 are optional, that is the number may consist of 1,2 or 3 digits in all.

Taking these into account, the overall regular expression can be represented as follows:

[1-9][0-9]{0,2}

User Spacemonkeys
by
7.2k points