How to eliminate a prefix string with all 0s

There have a set of strings, some of them are prefixed with 0, and others are not. For instance,

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?

Answers


Use REGEXPREP:

a = {'012AB','AB0','00230','0045','abc'};
a = regexprep(a,'^0+','')

ans = 

    '12AB'    'AB0'    '230'    '45'    'abc'

Need Your Help

Modifying Google OAuth2 login page

objective-c ios oauth-2.0

Is it possible to modify or show a more iOS friendly login page from googles oauth2 services? I'm not sure if I have seen a modified on before but i can't find any information on it. Any help would...

rotation along x and y axis

ios opengl-es-2.0 powervr-sgx

I'm using GLKit along with PowerVR library for my opengl-es 2.0 3D app. The 3D scene loads with several meshes, which simulate a garage environment. I have a car in the center of the garage. I am

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.