Wrapping paragraphs/new line in p tags

前端 未结 2 1518
孤独总比滥情好
孤独总比滥情好 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:33

    Try this

    (\w+\s+\d+)
    

    Then replace with

    <p>$1</p>
    

    See demo

    0 讨论(0)
  • 2021-01-24 18:46

    You can use this regex:

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

    and replace it with:

    <p>$1</p>\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.

    0 讨论(0)
提交回复
热议问题