MATLAB: How to use regular expression to remove a prefix string with all 0s.

regular expression

I have a set of strings, some of them are prefixed with 0, and others are not. For instance, there have five strings:
012AB AB0 00230 0045 abc
I want to remove all of the 0s if they are the prefix of a string. If a string does not have 0s at the prefix position, then the string will be kept the same.
Therefore, the above strings should be transferred into
12AB AB0 230 45 abc
How to implement the above functionality using regular expression?

Best Answer

s ='012AB AB0 00230 0045 abc';
out = regexprep(s,'\<0*','')