0

I have below inputs. I need to select string only numbers with or without comma using Regular expression

  1. 14,15,16

  2. 14,mps

  3. mps,13,12

  4. 12,13,mps

  5. 15,16

  6. 13

The regex will select only 1, 5 and 6. It will not select number with alphabets.

Can anyone help this...

I tried [0-9]+(\,[0-9]+)* but its not working.

Thomas Ayoub
  • 28,235
  • 15
  • 95
  • 135
ahtina b
  • 23
  • 6

1 Answers1

1

What you're after seems to be

^(?:[\d]+,?)+$

That'll match digits, optionally followed by a comma, and then repeated any number of times.

See it in action here at regex101.

SamWhan
  • 8,166
  • 1
  • 16
  • 44