Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript - Replace " ." with "." to eliminate spaces before dots

I've tried with replace(/ ./g, '.'); to eliminate the comma before the dot without succes. Any idea what is wrong? Thanks.

like image 990
zsola3075457 Avatar asked Nov 22 '25 11:11

zsola3075457


1 Answers

I presume your complaint is that every character followed by a space is being replaced with a .. This is because . is a wildcard character. Literally, it means "match anything except a newline":

(The dot, the decimal point) matches any single character except the newline characters: \n \r \u2028 or \u2029. (MDN)

You need to escape it if you want to match a literal .:

replace(/ \./g, '.')
like image 179
lonesomeday Avatar answered Nov 25 '25 00:11

lonesomeday



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!