简体   繁体   中英

How to remove space between period and the prior word

I have the following string:

"I like dogs ." 

I want to make it to this:

"I like dogs."

How can I do this using regex? I tried to do the following but it didn't work:

  var str = " I like dogs . ";
  str = str.replace(/\s+$/g, "");

There's no need to make it so complicated.

> "I like dogs .".replace(/\s+\./, ".");
"I like dogs."

Go for the easy approach, unless you have some odd layout elsewhere.

 str = "I like dogs ."; str = str.replace(/ \\./g, '.'); console.log(str); //output: I like dogs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM