Regex replace 0 in the list, but not 0 out of 10, 20, 30, etc. - using js replace

I am trying to create a regex to replace zeros in a list with an empty value, but not replace zeros in ten, twenty, thirty, etc.

list = 0,1,0,20,0,0,0,1, 1,3,10,30,0

desired list =, 1, 20 ,, 1, 1,3,10,30,

Using this in javascript replacement function

Any help / advice appreciated!

+6
source share
1 answer

It should be very easy to use word boundaries , \b0\b :

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

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

+8
source

Source: https://habr.com/ru/post/887047/


All Articles