I’m trying to create a regex that accept:
An empty string, a single integer or multiple integers separated by a comma but can have no starting and ending comma.
I managed to find this, but I cannot undertsand how to remove the digit limit
^\d{1,10}([,]\d{10})*$
The thing you posted still requires at least 1 integer, so it won’t match an empty string:
Here is what you need:
Explaination:
'?'so as to match the empty string.'\d+'.That is 1 or more digit characters('0'-'9')',\d+'and put an asterisk after it.3a. The inside means start with a ‘,’ then an integer.
3b. The asterisk means repeat everything inside the parenthesis 0 or more times.
Hench the whole thing is
either an empty string or start with an integer then repeat zero or more times a string which starts with a comma and ends with an integer