开发者

javascript turn single line break to double line break

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 ThisC开发者_高级运维ontent = ThisContent.replace(/(\n)/gm, "\n\n"); since it replace everything, including double line breaks.

What's the regex to do this?


txt = txt.replace(/(^|[^\n])\n([^\n]|$)/g, "$1\n\n$2");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜