最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin10PV0评论

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

Post a comment

comment list (0)

  1. No comments so far