Notepad++ newline in regex

狂风中的少年 提交于 2019-12-03 22:03:41

Notepad++ can do that comfortably, you don't even need regexes

In the find dialogue box look in the bottom left and switch your search mode to Extended which allows \n etc.

As odds on you're working on a file in windows format you'll be looking for \r\n (carriage return, newline)

a\r\nb\r\nc

Will find the pattern over three lines

darioo

Update 18th June 2012

With the new Notepad++ v6, you can indeed search for newlines with regexes. So you can just use

a\r\nb\r\nc

even with regular expressions to accomplish what you want. Note \r\n is Windows encoding of line-breaks. In Unix files, its just \n.

Unfortunately, you can't do that in Notepad++ when using regex search. Notepad++ is based on the Scintilla editor component, which doesn't handle newlines in regex.

You can use extended search for newline searching, but I don't think that will help you search for 3 lines.

More info here.

Update: Robb and StartClass0830 were right about extended search. It does work, but not when using regular expressions search.

^a\x0D\x0Ab\x0D\x0Ac

This will work \x0D is newline and \x0A is carriage return. Assumption is that each line in your file ends with ascii 10 and 13.

Kuchara

I found a workaround for this. Simply, in Extended mode replace all \r\n to a string that didn't exist in the rest of the document eg. ,,,newline,,, (watch out for special regexp chars like $, &, and *). Then switch to Regexp mode, do some replacements (now newline is ,,,newline,,,). Next, switch to Extended mode again and replace all ,,,newline,,, to \r\n.

Markstar

a\r\nb\r\nc works for me, but not ^a\x0D\x0Ab\x0D\x0Ac

Hmm, too bad that newline is not working with regular expressions. Now I have to go back to Textpad again. :(

In Notepad++ you can also try highlighting the desired part of the text and then pressing CTRL+J.

That would justify the text and thus removing all line endings.

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