开发者

Notepad++ newline Regex Issues [duplicate]

开发者 https://www.devze.com 2023-03-12 06:14 出处:网络
This question already has answers here:开发者_运维百科 Closed 10 years ago. Possible Duplicate: Find CRLF in Notepad++
This question already has answers here: 开发者_运维百科 Closed 10 years ago.

Possible Duplicate:

Find CRLF in Notepad++

I am trying to use notepad++ for some simple regex find and replace. But when I try to use the regular expression syntax for a new line (\r\n) I get the folowing error:

can't find the text: "\r\n"

\r\n works in "Extended" search and in other text editors, but not in the Regular Expression search.

Any ideas?


Notepad++'s regex engine doesn't support multiple lines, so newline characters can't be matched. If you need to find and replace blank lines, you need to use extended search. This is no longer true as of Notepad++ 6.0, which now uses PCRE as its regex engine and allows for multi-line replacements. See the accepted answer to the duplicate question for more info.


From Notepad++ help file:

Because Notepad++ makes use of the Scintilla regex engine, it is the same as with SciTE, so a full list of regex options can be found here (with the difference that POSIX mode is always on, this is not an option): http://www.scintilla.org/SciTERegEx.html


From SciTE docs:

Note that \r and \n are never matched because in Scintilla, regular expression searches are made line per line (stripped of end-of-line chars).


From Notepad++ original replace options, "Extend" mode support \r\n, so you can just replace every newline to an unique short string that never appeared in your document, e.g. abcdefg, to make a huge one line string. Then you can do your regex replace job in the "Regex" mode, try to keep the unique tag string, replace \r\n back using "Extend" mode, done, inconvenient, and stupid.

0

精彩评论

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