I am using regex to assert that my string is a combination of a maximum of 4 numbers separated by commas, the numbers must be between 1 and 4. Examples of valid strings would be :
1,2,3
1,2
1
1,2,3,4
4,1
To achieve this i am using ^[1-4](,[1-4])*$
, but i am not able to limit the number of characters on the string. so in my implementation the following string is also valid 1,2,3,4,2,3
which is against what i am trying to achieve.