user13763372
user13763372

Reputation: 13

Regex for htaccess greater than 10

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

Answers (2)

gawkface
gawkface

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:

  • 1[1-9] - exactly 2 digits, 11 to 19
  • [2-9]+\d+ Here:
    • [2-9]+ means 1 or more digits in range 2-9
    • \d+ - any digit 1 or more occurrence
  • 1\d\d+ - 3 and more digit numbers starting with digit 1

Upvotes: 0

Wiktor Stribiżew
Wiktor Stribiżew

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:

enter image description here

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

Related Questions