Skip to content

Instantly share code, notes, and snippets.

@ramons03
Last active February 28, 2024 23:10
  • Star 50 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ramons03/6152802 to your computer and use it in GitHub Desktop.
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.
@nadsberces
Copy link

nadsberces commented Feb 4, 2020

is it possible to increment number components in a selection? for example i have

"number": 1,
etc..
"number": 2,
etc..
"number":3

then i want to find "number:" and add 1 to the numbers following it so that i get
"number": 2,
etc..
"number": 3,
etc..
"number":4

@RajaSurapaneniTR
Copy link

How do we search for [a-z]$[a-z] $ preceded and succeeded by a lower case char

@Beckfield
Copy link

Beckfield commented May 1, 2020

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?

@abeypa
Copy link

abeypa commented Jul 7, 2021

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

@ArastaD0t
Copy link

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

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

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