Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Notepad++ Advanced search and replace. Null, Enter char, Tab, Regular Expressions, Etc.
Open the find/replace dialog.
At the bottom will be some Search mode options. Select "Extended (\n \r \t \0 \x...)"
In either the Find what or the Replace with field entries, you can use the following escapes:
\n new line (LF)
\r carriage return (CR)
\t tab character
\0 null character
\xddd special character with code ddd
- [!] finds the exclamation character.
- .* selects the rest of the line.
- (\+.*)(Item) \+ finds the + character. | .* selects the text after the + up until the word "Item" | Item finds the string "Item" | () allow us to access whatever is inside the parentheses. The first set of parentheses may be accessed with \1 and the second set with \2.
- \1\r\n\2 will take + and whatever text comes after it, will then add a new line, and place the string "Item" on the new line.
- A-Z finds all letters of the alphabet in upper case.
- a-z finds all lower case letters.
- A-Za-z will find all alphabetic characters.
- [^...] is the inverse. So, if we put these three together: [^A-Za-z] finds any character except an alphabetic character.
- Notice that only one of the [^A-Za-z] is in parentheses (). This is recalled by \1 in the Replace with field. The characters outside of the parentheses are discarded.
@abeypa
Copy link

abeypa commented Jul 7, 2021

image
how to remove the last ";" from each line using replace

@ArastaD0t
Copy link

ArastaD0t commented Jan 24, 2022

Hi i use np ++ for translating game, example i need find word Settings , how i can find word Settings anywhere without name="Settings" and string="Settings" ? Thx for Help, and sorry for my Bad English.

@ArastaD0t
Copy link

ArastaD0t commented Jan 24, 2022

How i can replace Word in multiple Directories ? Be like C:\Program Files\Client1* C:\Program Files\Client2*

@Coldblackice
Copy link

Coldblackice commented May 3, 2022

When I press the Enter key while editing an indented line, the cursor begins the next line aligned with the indentation of the previous line. When I use '\n' or '\r' in a search/replace operation, it does not align to the indentation of the previous line. Am I doing something wrong? It seems to me that '\r' should act just like the Enter key, no?

I realize this is old, but for anyone's future reference, the issue is that while Notepad++ automatically inserts previous indentation when inputting new lines, the search/replace function isn't aware of this. You need to include the necessary indentation in your search/replace.

The easiest way is merely drag-selecting the beginning part of that line (the empty indentation spacing) and then press CTRL-H to open "Replace" dialog. It will be pre-filled with the necessary search to locate that pattern of indentation. And then you can prepend a "\n" to the start of it to only search for new lines that start with that level of indentation.

Depending how your NP++ is set up to manage indentation - i.e. a tab vs. spaces - you may be able to utilize extended-search's "\t", which indicates a "tab".

For reference, an "Enter" for a newline (as it seems you're asking) equates to "\r\n", which is a carriage return + line-feed/newline operation, which is what the "CR LF" symbols are referencing at the end of each line, if you were to enable "Show symbols". This is a throwback reference to the days of the typewriter, where the "Enter" button equivalent merely dropped the cursor down one line, but wouldn't automatically bring it to the leftmost start of the line by default.

@Coldblackice
Copy link

Coldblackice commented May 3, 2022

image how to remove the last ";" from each line using replace

Enable the "Extended" search selector, and then in the "Find" box, add an "\r\n" to the right of your semicolon, e.g. ";\r\n". That will find only semicolons that are at the end of lines.

Note that if you are doing a "Replace" operation, you'll also need to add the "\r\n" to the end of the replace-text, otherwise the newline's will be removed, making it one long continuous line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment