Home > database >  Regular expresion for 000 to 999
Regular expresion for 000 to 999

Time:07-02

I try to create a regular expression that allow me to filter values that start with these ranges: 000 to 999

I try with this ^[001-999]{3}$ but it doesn't work well with ranges to 000 to 099

Thanks for your help

CodePudding user response:

This should work for you:

^\d{1,3}$

Here's a visualization to explain what this pattern is doing.

If you only want exactly three digits, use {3} instead of {1,3} (which will also allow 1 or 2 digits): ^\d{3}$

If your regex engine does not support \d, use [0-9] instead: ^[0-9]{3}$

  • Related