I'm trying to create a regex to replace zeros in list with an empty value but not replace the zeros in ten, twenty, thirty, etc.
list = 0,1,0,20,0,0,1,,1,3,10,30,0
desired list = ,1,,20,,,1,,1,3,10,30,
Using this in the javascript replace function
Any help/tips appreciated!
I'm trying to create a regex to replace zeros in list with an empty value but not replace the zeros in ten, twenty, thirty, etc.
list = 0,1,0,20,0,0,1,,1,3,10,30,0
desired list = ,1,,20,,,1,,1,3,10,30,
Using this in the javascript replace function
Any help/tips appreciated!
Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked May 1, 2011 at 11:56 shaunwshaunw 3734 silver badges11 bronze badges1 Answer
Reset to default 8Should be very simple using word boundaries, \b0\b
:
s = s.replace(/\b0\b/g, '');
Working example: http://jsbin./ipuru4