Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
627 views
in Technique[技术] by (71.8m points)

javascript - Help with regexp replacing every second comma in the string

I have a string of that displays like this....

1235, 3, 1343, 5, 1234, 1

I need to replace every second comma with a semicolon

i.e.

1235, 3; 1343, 5; 1234, 1

the string length will always be different but will follow the same pattern as the above i.e. digits comma space digits comma space, etc.

how can I do this with javascript? Is it possible?

Thanks, Mike

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
'1235, 3, 1343, 5, 1234, 1'.replace(/([0-9]+),s([0-9]+),s/g, '$1, $2; ')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...