admin管理员组文章数量:1025217
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
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
本文标签:
版权声明:本文标题:javascript - regex to replace 0 in list but not 0 of 10, 20, 30, etc. - using js replace - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1744825114a2118825.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论