Replace Rows in Notepad++

2019-09-20 05:25发布

问题:

I'd like to convert stuff like this:

bitte
----------

dream
----------


----------

HD
----------

ready
----------

into stuff like this:

bitte:dream
HD:ready

using a regex. What regex to use? How to put all this rows together?

回答1:

You may use a regex like

^(?:---+\R\s*)*(\w.*)\R---+\R(?:\h*\R)*(\w.*)\R---+$

And replace with $1:$2.

The ^ matches the line start, (?:---+\R\s*)* matches optional delimiter lines before the first non-empty line, (\w.*) is Group 1 capturing a word char followed with 0+ chars other than a newline, \R---+\R matches a line break followed with 3+ hyphens and a linebreak, (?:\h*\R)* matches n number of blank lines, (\w.*) (see above) and \R---+$ matches a linebreak and 3+ hyphens at the end of the line.



回答2:

Find what: \W*(\w+.*)[\r\n]+\-{5,}\s+(\w+.*[\r\n]+)\-{5,}\W*
Replace with: $1:$2

Assuming it's always more than 5 dashes.

The newline after the second word is already in the 2nd capture group.