task: input only numbers from 16 to 100; how can you make a regular expression from 16-100, or can there be any other way?

Regex inputRegex = new Regex(@"^[16-100]$"); //так не работает! 
  • A digit is a symbol from zero to nine. Regular expressions are created to search for substrings, for entering the number of a limited range, it is better to cast to the desired size, cyclic input to a suitable value, or other tricks that experts advise. - AivanF.
  • one
    In what sense does "not work"? You created a regular season, and for some reason it did not apply magically to the text? - VladD
  • @VladD Regularly just does not work because it is fundamentally a mistake. - vitidev
  • @vitidev: This is yes, but there is no binding in the question, so I ventured to assume that it is not at all. - VladD

1 answer 1

dialects of regular expression engines, of course, may differ.

here is the head-on solution for the extended regular expression:

 ^(1[6-9]|[2-9][0-9]|100)$ 

the brackets are limited to three options, the options are separated by characters | :

 1[6-9] [2-9][0-9] 100 

first option: the character 1 , followed by any of the characters from the range 6-9 .

second option: any of the characters from the range of 2-9 , followed by any of the characters from the range of 0-9 .

third option: just three characters 100 .