tags:

views:

23517

answers:

7

How can I find/replace all CRLF characters in notepad++? Looking for something equivalent to the ^p special character in Word.

A: 

Assuming it has a "regular expressions" search, look for \r\n. I prefer \r?\n, because some files don't use carriage returns.

EDIT: Thanks for the feedback, whoever voted this down. I have learned that... well, nothing, because you provided no feedback. Why is this wrong?

Chris Marasti-Georg
I'm not sure exactly why it doesn't work but it doesn't. I'm assuming that this regex implementation (in Notepad++) only checks a single line at a time and ignores any new line characters. That's probably why you were voted down.
luckyllama
yep. regex is line by line in notepad++, so you can match positionally at EOL with $ but can not search/replace expressions that cross line boundaries.
Warren P
+7  A: 

[\r\n]+ should work too

Actually no, it does not seem to work with regexp...

But if you have notepad++ 5.x, you can use the 'extended' search mode and look for \r\n. That does find all your CRLF.

(I realize this is the same answer than the others, but again, 'extended mode' is only available with Notepad++4.9, 5.x and more)

VonC
I was running v 4.7. Upgraded to the newest version and extended mode works as advertised. Thanks to all who responded.
polara
+1: I was running 4.6, and had a similar problem. And thanks to your answer, I upgraded to 5+. Thanks!
paercebal
It works! But this makes Notepad++ RegExp suck. UltraEdit-32 is smarter, you just need \n and you've finished your job...
thenonhacker
\r\n worked for me, but not \n, which is kind of counter-intuitive if you're a developer who is used to \n being shorthand for \r\n.
Warren P
+2  A: 

On the Replace dialog, you want to set the search mode to "Extended". Normal or Regular Expression modes wont work.

Then just find "\r\n" (or just \n for unix files or just \r for mac format files), and set the replace to whatever you want.

Nathen Silver
A: 

I've not had much luck with \r\n regular expressions from the find/replace window.

However, this works in Notepad++ v4.1.2:

  1. Use the "View | Show end of line" menu to enable display of end of line characters. (Carriage return line feeds should show up as a single shaded CRLF 'character'.)

  2. Select one of the CRLF 'characters' (put the cursor just in front of one, hold down the SHIFT key, and then pressing the RIGHT CURSOR key once).

  3. Copy the CRLF character to the clipboard.

  4. Make sure that you don't have the find or find/replace dialog open.

  5. Open the find/replace dialog. The 'Find what' field shows the contents of the clipboard: in this case the CRLF character - which shows up as 2 'box characters' (presumably it's an unprintable character?)

  6. Ensure that the 'Regular expression' option is OFF.

Now you should be able to count, find, or replace as desired.

A: 

Use the advanced search option (ctrl-R) and use the keyboard shortcut for CRLF (ctrl-M) to insert a carriage return.

+5  A: 

It appears that this is a FAQ, and the resolution offered is:

Simple search (Ctrl+H) without regexp

You can turn on View/Show End of Line or view/Show All, and select the now visible newline characters. Then when you start the command some characters matching the newline character will be pasted into the search field. Matches will be replaced by the replace string, unlike in regex mode.

Note 1: If you select them with the mouse, start just before them and drag to the start of the next line. Dragging to the end of the line won't work.

Note 2: You can't copy and paste them into the field yourself.

Advanced search (Ctrl+R) without regexp

Ctrl+M will insert something that matches newlines. They will be replaced by the replace string.

sundar
You can use Ctrl+M to insert newlines in the replace string as well.
Dusty Campbell
It's a FAQ because this is a bit of a design wart in an otherwise brilliant product.
Warren P
A: 

Just to build a little on what 'thenonhacker' was mentioning. We use ULtraEdit-32 on the job, and working with EDI files (x.12), we often have to wrap or unwrap data. The 2 most common Search & Replace strings are "^p" & "~". going one way will replace the "~" with a CR/LF for easier reading of each segment. Going the other way puts the file back into the format the EDI translator needs.

For lazy people like myself, I just have those map'd to keys for easy of use.

DavidGrove