我用这个打了一堵砖墙......
我已经设法删除了Chars,但是正在寻找删除所有WhiteSpaces,Carrige Returns&删除Chars后每个条目开头的0。
var p_string = 'OPS010001 BLW020002 MKS030003';
var p_data = p_string.split(/[^0-9]+/g);
$('body').html(p_data + '<BR>');
答案 0 :(得分:0)
使用string.replace
功能。
string.replace(/^0|\s/g, "");
\s
匹配空白字符,包括换行符。
答案 1 :(得分:0)
你想要这样的东西
var p_data = p_string.split(/[^0-9]+/g).map(function(x){
return x.replace(/^0|\s/g, ""); // remove space, carriage return and 0 at start
}); // you can use Array.join to join the array with separator of your choice