Reputation: 13
I'm not very good at regular expressions... The only thing I want to achieve is to match in the htaccess when the page number is greater than 10. I've tried the following regular expression:
^(\d\d\d*)$
but it matches 10, because it's the first two-digit number.
Any ideas? Thank you!
Upvotes: 1
Views: 2553
Reputation: 2322
^(1[1-9]|[2-9]+\d+|1\d\d+)$
You may test it in https://regex101.com (it has great explanation for each step even)
I used scenarios: 9, 10, 11, 20, 009, 09, 300, 4445, 100
Explanation: the OR (|) operator separates 3 regex expressions:
Upvotes: 0
Reputation: 627537
You need
^(?:1[1-9]|[2-9]\d|[1-9]\d{2,})$
If you need to allow any amount of leading zeros, you may use
^0*(?:1[1-9]|[2-9]\d|[1-9]\d{2,})$
See the regex demo and the regex graph:
Details
^
- start of string(?:1[1-9]|[2-9]\d|[1-9]\d{2,})
:
1[1-9]
- 11
to 19
|
- or[2-9]\d|
- 20
to 99
, or[1-9]\d{2,}
- 100
and more$
- end of string.Upvotes: 1