string.replace() with RegEx replaces wrong characters
Problem
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?
Problem courtesy of: jonasonline
Solution
Use this regex
[\n\r]+\.(?=[\s\n\r]+)
replace it with .
Solution courtesy of: Anirudha
Discussion
View additional discussion.