string.replace() with RegEx replaces wrong characters

I am trying to use a regex (javascript) to move periods in a text. The text looks like this:

This is a text with ending period on wrong line
.
This is a another line

I use this regex:

summary.replace(/[\n\r]\.[\s\n\r]/gm, '.\r')

to make it look like this:

This is a text with ending period on wrong line.
This is a another line

But instead it looks like this:

This is a text with ending period on wrong line
.his is a another line

Cant figure out what is wrong in my regex.

Anyone?

I would suggest you output the result encoded as JSON with JSON.stringify to see if there are any whitespace characters (like newlines) that are still there. I would also use quantifiers for you character classes so that it can match more that one character at once

/[\n\r]?\.[\s\n\r]*/gm

Use this regex

[\n\r]+\.(?=[\s\n\r]+)

replace it with .