Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex to replace 0 in list but not 0 of 10, 20, 30, etc. - using js replace

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!

like image 468
shaunw Avatar asked May 01 '11 11:05

shaunw


1 Answers

Should be very simple using word boundaries, \b0\b:

s = s.replace(/\b0\b/g, '');

Working example: http://jsbin.com/ipuru4

like image 148
Kobi Avatar answered Sep 21 '22 00:09

Kobi