[英]Remove spaces from javascript string but not all spaces
I have a string 我有一个弦
str = 'first last1; first last2; first Last3;';
I am looking to remove the spaces only after the semicolons. 我希望仅在分号后删除空格。
I have tried using 我尝试使用
str = str.replace(';' + /\s+/g, ';');
and 和
str = str.replace((';' + /\s+/g), ';');
but it is not working. 但它不起作用。
any help would be appreciated. 任何帮助,将不胜感激。
str = 'first last1; first last2; first Last3;'; str = str.replace(/;\\s+/g, ';'); alert( str );
You were quite close: 您非常接近:
str = str.replace(/;\s+/g, ';');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.