开发者

javascript turn single line break to double line break

开发者 https://www.devze.com 2022-12-29 16:55 出处:网络
Hm... I\'m trying to convert single line break into double line break, as in This is a sentence. This is another sentence.

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

精彩评论

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

关注公众号