[英]How to remove space between period and the prior word
我有以下字符串:
"I like dogs ."
我想做到这一点:
"I like dogs."
我怎样才能使用正则表达式做到这一点? 我尝试执行以下操作,但没有奏效:
var str = " I like dogs . ";
str = str.replace(/\s+$/g, "");
没有必要让它变得如此复杂。
> "I like dogs .".replace(/\s+\./, ".");
"I like dogs."
选择简单的方法,除非您在其他地方有一些奇怪的布局。
str = "I like dogs ."; str = str.replace(/ \\./g, '.'); console.log(str); //output: I like dogs.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.