[英]Javascript Regex - Remove Chars, WhiteSpace & Starting 0
我已经用这个砸了墙。
我设法删除了字符,但是在删除字符后,希望在所有条目的开头都删除所有空白,Carrige Return和0。
var p_string = 'OPS010001 BLW020002 MKS030003';
var p_data = p_string.split(/[^0-9]+/g);
$('body').html(p_data + '<BR>');
使用string.replace
函数。
string.replace(/^0|\s/g, "");
\\s
匹配空格字符,包括换行符。
你想要这样的东西
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.