I need a .Net (C#) Regex to match a comma separated list of numbers that will not match if there is a comma as the last character
123,123,123,123 true - correct match
123,123,123,123, false - comma on end
123,123,123,,123 false - double comma
,123,123,123,123 false - comma at start
"" false - empty string
123 true - single value
I have found this Regex but matches when there is a comma on the end ^([0-9]+,?)+$
What would be a Regex pattern that would fit this pattern?
EDIT: Added 1 example for clarity the correct answer works for 123
Try using this pattern:
^([0-9]+,)*[0-9]+$
You can test it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With