Friday, January 28, 2011

Notepad2 tips to find and replace newlines

If you want to search in a textfile for newline (aka line break or end-of-line (EOL) character) here are some tips when using Notepad2.

Newline is typically defined with a character set of either LF (Line feed, '\n', 0x0A, 10 in decimal) or CR (Carriage return, '\r', 0x0D, 13 in decimal) individually, or CR followed by LF (CR+LF, '\r\n', 0x0D 0x0A).

This from from the Notepad2 FAQ:

Can I do multiline find and replace?
This is possible when activating the Transform backslashes option in the find and replace dialog boxes. Enter \n to represent the LF character, or \r for the CR. If line ending mode is set to Windows (CR+LF), \r\n has to be used to represent newline sequences.

To perform a replacement operation with multiline text as the replacement, it's easier to copy the text to the clipboard first, and then use ^c as a placeholder for the clipboard contents in the replacement field.

Here is an example where I add extra newlines by searching for \n and replace with \n\n.

Here is the result of it. Note that Transform backslashes must be checked.

Another thing that can be useful is how to handle tab characters.

If you activate Regular expression search in the find and replace dialog boxes, the \t sequence represents a tab character both in the find and in the replace text.

No comments:

Post a Comment

Subscribe to the comments feed

Some of the latest blog posts

Subscribe to RSS headline updates from:
Powered by FeedBurner

Contact Us | About JTB World | Subscribe to this blog
JTB World's website | Website General Terms of Use | Privacy Policy
^ Top of page

© 2004- JTB World. All rights reserved.