a) Start and end with a number b) Hyphen should start and end with a number c) Comma should start and end with a number d) Range of number should be from 1-31
Using the same logic in my previous answer but limiting the range
A becomes [1-9]\d|3[01] B becomes ([1-9]\d|3[01])|(([1-9]\d|3[01])-([1-9]\d|3[01]))
[1-9]\d|3[01]
([1-9]\d|3[01])|(([1-9]\d|3[01])-([1-9]\d|3[01]))
Overall expression
(([12]\d|3[01])|(([12]\d|3[01])-([12]\d|3[01])))(,(([12]\d|3[01])|(([12]\d|3[01])-([12]\d|3[01]))))*