Wrapping paragraphs/new line in p tags

前端 未结 2 1519
孤独总比滥情好
孤独总比滥情好 2021-01-24 18:02

I have multiple text file and need to wrap each paragraph in p tags using regex.

i.e. before:

Paragraph 1

Paragraph 2

Paragraph 3

Aft

2条回答
  •  粉色の甜心
    2021-01-24 18:46

    You can use this regex:

    (.+?)(\n|$)+
    

    and replace it with:

    $1

    \n\n

    The problem with your regex is, that it is matching empty lines as well, because you're saying: "Match any character zero or more times, followed by a new line".

    You also have to take in count the last paragraph, that might not end with a line break.

提交回复
热议问题