Replace Rows in Notepad++

梦想与她 提交于 2019-12-13 08:00:53

问题


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.



来源:https://stackoverflow.com/questions/38531515/replace-rows-in-notepad

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!