3

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?

Community
  • 1
  • 1
chris
  • 216
  • 1
  • 2
  • 7
  • Try `[\r\n]+` instead? Order of return/new line may be reversed. Placing them in a class insures they match (in either order) but in succession. (Alternatively, you can use `[\r\n]{1,2}` to find single instances of the return.) – Brad Christie Jun 10 '11 at 17:21
  • @bazmegakapa you're right, I just didn't see it because they used CRLF rather than \r\n – chris Jun 13 '11 at 13:24

3 Answers3

5

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.

Community
  • 1
  • 1
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • According to a post in [June 2008](http://markantoniou.blogspot.com/2008/06/notepad-how-to-use-regular-expressions.html) the regex engine appears to acknowledge `\r`,`\n` (among others including `\t`, `\b`, etc.). -- EDIT: Also found [this post](http://markantoniou.blogspot.com/2009/02/regular-expressions-guide.html) mentioning to use `ctrl+Q,ctrl+J` to insert a new line in the pattern field. – Brad Christie Jun 10 '11 at 17:23
  • @Brad Christie, there are 3 search modes: normal, extended, and RegEx. The normal mode is *normal*, the extended mode allows newlines tabs and a few other selectors, and the RegEx mode is allows for a limited regex search. – zzzzBov Jun 10 '11 at 17:25
  • @Brad Christie: I never got that to work. Re your edit, isn't that for emacs? – BoltClock Jun 10 '11 at 17:25
  • @zzzzBov: Ah, that may be the different, need to use extended. @BoltClock: Try the `ctrl+Q,ctrl+J`. I'm kind of curious if that works. – Brad Christie Jun 10 '11 at 17:26
  • It has an "emac equivalent", so I just assume it works for both. I may be wrong (I personally use notepad2 over notepad++, so (unfortunately) I can't test, and thus I'm not posting any answer(s).) – Brad Christie Jun 10 '11 at 17:27
4

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).

Amber
  • 507,862
  • 82
  • 626
  • 550
  • hmm if this is the case, does anyone know of any good free text editors for windows that support RegEx with end-of-line chars? – chris Jun 13 '11 at 13:27
  • New in version 7, [EditPad Lite](http://www.editpadlite.com/) now features regex search-and-replace. I've been using EditPad **Pro** for years, and it has the best regex support I've ever seen in an editor. – Alan Moore Jul 31 '11 at 03:41
2

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.

Zsolt Botykai
  • 50,406
  • 14
  • 85
  • 110