Answer the question
In order to leave comments, you need to log in
How to set a range of digits in nginx (regular expression)?
There is a certain url that ends with a number. I need one rule to work with one range (for example, up to a thousand), and another rule for the rest. I have already found the required line in the config, but I can’t set the range (
As an example - [0-9] for all digits, but I need a certain range. Optional - it can be by value, i.e. two-digit / three-digit, etc.
Answer the question
In order to leave comments, you need to log in
Probably something like this
location ~ "^/[\d]{2}" {
# ...
}
location ~ "^/[\d]{3}" {
# ...
}
location ~ "^/[\d]{4}" {
# ...
}
Well, regular expressions don't work with numbers, they don't work
They work with strings
You need to specify a regular expression for which the string matches from '1' to ''1000'' - at least you can check the number of consecutive digits in a string in a string. There are quantifiers for this.
You can use this approach.
https://stackoverflow.com/questions/8592488/regex-...
But in general, it's better to parse request parameters inside the application, and not in Nginx.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question