Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression for number and slash

Tags:

c#

regex

I do not know regular expressions and going crazy to find one that accepts formats consisting on numbers and slash. For example:

  • 5
  • 5/10
  • 10/15/30
  • 10/20/120
  • 20/120/250/300
like image 743
woller Avatar asked Jan 22 '26 14:01

woller


1 Answers

This should work:

^\d+(\/\d+)*$

Look at the examples.

This means:

  1. My string must begin (^) with a one or more digit (\d+)
  2. Optionally ((..)*) followed by a slash and one or more digit (\/\d+), even many times (* means from 0 to many)
  3. And then it must end ($).
like image 123
Andrea Salicetti Avatar answered Jan 25 '26 03:01

Andrea Salicetti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!