MATLAB: Replace repeated symbol by regexprep

regexprep replace repeating symbols

Hello, dear Matlab experts, I'd like to change i.e. string '1,31,' to '1,31' by using regexprep. So I need to replace second, third and others commas (or to keep only the first one). There is a plenty of characters and quantifiers for using in expression but I can not find one appropriate. I.e. I use
regexprep ('1,31,',',[1]',',')
but nothing changes.

Best Answer

regexprep('1,31,7,2', '(?<=,.*?),', '', 'all')