Skip to content

Instantly share code, notes, and snippets.

@ramons03
Last active September 27, 2024 21:12
Show Gist options
  • Save ramons03/6152802 to your computer and use it in GitHub Desktop.
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.
@tware667
Copy link

tware667 commented Sep 1, 2018

Hi

How would I find all numbers of the form

spacen:n where nn can be any number, single or multi digit, e.g. 2:14 or 23:9, or whatever?

thanks
TW.

@ColinDave
Copy link

Hi

How would I find all numbers of the form

spacen:n where nn can be any number, single or multi digit, e.g. 2:14 or 23:9, or whatever?

thanks
TW.

I know this is quite old, but for people with a similar problem, maybe something like this:
([0-9])[^:]
([0-9]) is the group for all numbers, and [^:] breaks that group if there's a colon (poorly explained due to the lack of my english knowledge)

@7thstorm
Copy link

7thstorm commented Apr 17, 2019

Is there a way to identify a file if something is NOT present?
For example, show files that do not have any instances of "PEAR" "APPLE" "BANANA"
i.e show all files that do not have any of these

@Vijayakumar144
Copy link

Hi
i want how to remove 1,2,5,6,9,10........ & 3,4,7,8,11,12........ line in notepad++.
Is there a way to delete line in that order?

@mgoebel97
Copy link

I am hoping you can help me. I have a txt file with about 2000 characters. I want to find a word on char 123 but change the information in char 1662. I have tried to use the in selection but it does not work.
This is what I have: FIND WHAT: ^.{123}\K05
REPLACE WITH: [-c1662]2FIRST COMMONWEALTH BANK

It finds the character no problem but does not replace anything

@ankushkgarg
Copy link

ankushkgarg commented Dec 1, 2019

I want to remove " 2567 " in "(2567, 510,........... )" including space after numbers(without quotes) and wants the output: (510,.....)
what will be regex in Find What: ??
and what is to be write in Replace With: ??

@Gururajv007
Copy link

Expert advice needed please : I would like to remove the last column from | symbol on wards in below. Pl help.
A | 123|101|Roast
B | 137|201|Flower
C | 117|abcd|Just
D | 367|effg|Apple1

Data needed like below
A | 123|101
B | 137|201
C | 117|abcd
D | 367|effg

@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