-1

How to put a number greater than 9 to regexp character set?

For example, I can do ^[01236]$, but what if I want to put 100 as an option to the set?

How do I solve this problem?

Emma
  • 27,428
  • 11
  • 44
  • 69
sgon00
  • 4,879
  • 1
  • 43
  • 59
  • Regular expressions don't understand numeric values. They only match patterns of characters. If you want to test the numeric value of a string, use your host language. – Andy Lester Mar 02 '19 at 06:09
  • 1
    @AndyLester yeah, you're right. Thanks for the tip. – sgon00 Mar 02 '19 at 06:13

3 Answers3

2

If a number is greater than 9, it is more than 2 digits and the first digit is not 0. So the regex you might want to use is: ^[1-9][0-9]+$

dekauliya
  • 1,303
  • 2
  • 15
  • 26
2

'\d+' can find number having 1 or more digits

amol goel
  • 149
  • 3
1

If you want to put a specific multi character strings you can use:

^(10|100|200|301|601)$

Which will match 10, 100, 200, 301, and 601

test: https://regex101.com/r/bptbsx/1

cybernetic.nomad
  • 6,100
  • 3
  • 18
  • 31