function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vijay NagarathinamVijay Nagarathinam 

Regular expression issue

Hi All,

What is the purpose of the below regular expression?

string test = '00045304^+453534$!';
system.debug('>>>> Remove leading zero >>'+test.trim().replaceAll('^0+(?!$)', ''));

Thanks,
Vijay
 
Ankur Saini 9Ankur Saini 9
Hi Vijay,

If you have to remove all special characters from this string, use : 
string test = '00045304^+453534$!';
system.debug('>>>> Remove leading zero >>'+test.replaceAll('[^a-zA-Z0-9]', ''));
or
system.debug('>>>> Remove leading zero >>'+test.trim().replaceAll('[0+(?!$)]', ''));

If you have to remove all alphanumeric characters from this string, use : 
string test = '00045304^+453534$!';
system.debug('>>>> Remove leading zero >>'+test.replaceAll('[a-zA-Z0-9]', ''));
or
system.debug('>>>> Remove leading zero >>'+test.trim().replaceAll('[^0+(?!$)]', ''));

Thanks,
Ankur Saini
http://mirketa.com