为了更加直观,有些号码需要加空格:

// 拼接空格,每4位加一个空格
let bankAccount = '6228888888888888888';
let blank_value = bankAccount.replace(/\s/g,'').replace(/(.{4})/g,"$1 ").trim();
console.log(blank_value);

字符串去中间空格:

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
// 字符串去中间空格
let value = 'ab cd efg';
let temp = value.replace(/[ ]/g, "");
console.log(temp);

字符串去首尾空格:

let str = '  abcdefg   ';
let new_str = str.trim();
console.log(new_str);

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄