tags:

views:

64

answers:

1

Hm... I'm trying to convert single line break into double line break, as in

This is a sentence.
This is another sentence.

into

This is a sentence.

This is another sentence.

Apparently this doesn't work ThisContent = ThisContent.replace(/(\n)/gm, "\n\n"); since it replace everything, including double line breaks.

What's the regex to do this?

+2  A: 
txt = txt.replace(/(^|[^\n])\n([^\n]|$)/g, "$1\n\n$2");
Amarghosh
It seems to replace \n\n also. Those sentences that already have double linebreak becomes triple linebreaks.
Eric Sim
@Eric remove the m flag and it'll work
Amarghosh