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

I'm trying to create a regex to replace zeros in list with an empty value but not replace the zero

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 badges
Add a ment  | 

1 Answer 1

Reset to default 8

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

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

Working example: http://jsbin./ipuru4

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744825116a4595746.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信