javascript - js regular matching problem
PHP中文网
PHP中文网 2017-05-16 13:03:28
0
2
371

Use regular matching, only numbers and commas are allowed

var str = "2456789,2345678765432,,,,234567876543,,,45678976543,,,,3456765432";

The comma in the middle of the number is only allowed to appear once; replace more with empty; how to write. Where is the master...
The desired results are 2456789, 2345678765432, 234567876543, 45678976543, 3456765432;

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(2)
洪涛

replace(/,+/g, ",")

我想大声告诉你
var re = /\d+\,?/g;
var str = "2456789,2345678765432,,,,234567876543,,,45678976543,,,,3456765432";
var myArray = str.match(re);
console.log(myArray);
VM389472:4 (5) ["2456789,", "2345678765432,", "234567876543,", "45678976543,", "3456765432"]
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template