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.
@avinav597

This comment has been minimized.

Copy link

@avinav597 avinav597 commented Mar 12, 2016

How to make the program replace only in selected region.

@eproffitt

This comment has been minimized.

Copy link

@eproffitt eproffitt commented Apr 13, 2016

@avinav597 When the user highlights a selection and then presses 'Ctrl+H' in order to display a Find and Replace modal, there is an "In Selection" checkbox next to the "Replace All" button.
notepad _replace_all_in_selection

@u01jmg3

This comment has been minimized.

Copy link

@u01jmg3 u01jmg3 commented Jul 29, 2016

Any way of preserving case during a find/replace?

e.g.

userlogin => consumerlogin,
USERLOGIN => CONSUMERLOGIN,
UserLogin => ConsumerLogin,

This works but obviously the strings are static which is not ideal for quick usage. It also only covers lowercase, UPPERCASE and Sentence case rather than respecting case as a whole.

  • Find: (?:(U|(u))((?:(SER|(ser)))))
    • (Match case must be ticked)
  • Replace: (?2:\u)(?5:\U)consumer
@debrajrakshit

This comment has been minimized.

Copy link

@debrajrakshit debrajrakshit commented Aug 26, 2016

How to remove a new line? So where it is \n I want to replace it with a space and make it on same line.

@HatemHusam

This comment has been minimized.

Copy link

@HatemHusam HatemHusam commented Sep 6, 2016

How to find all the lines that ends with com. ( Com + . )

@bhushanbaviskar

This comment has been minimized.

Copy link

@bhushanbaviskar bhushanbaviskar commented Nov 11, 2016

Same question -> How to remove a new line? So where it is \n I want to replace it with space and make it on the same line.

@newbiegirl

This comment has been minimized.

Copy link

@newbiegirl newbiegirl commented Nov 21, 2016

Please assist, I am trying to find a specific ASCII symbol and I need to replace is with another. How do I do that. I used the find function in Search > Find Character in Range however it does not allow to me to search for a specific ascii number (148) and I need to replace that with an another symbol.

@sverremb

This comment has been minimized.

Copy link

@sverremb sverremb commented Jan 6, 2017

To replace a blank line, use \n\r

@lukegaylor

This comment has been minimized.

Copy link

@lukegaylor lukegaylor commented Feb 13, 2017

I want to find and replace all the `\cite{......}´commands with blanks. the dots are different for each reoccurrence of \cite. What do i need to input into notepad++

@MelioraCogito

This comment has been minimized.

Copy link

@MelioraCogito MelioraCogito commented Mar 11, 2017

Actually \n\r doesn't work (v7.3.2). Use \r\n instead. Works like a charm.

@disco0

This comment has been minimized.

Copy link

@disco0 disco0 commented Jul 1, 2017

Thanks for this, got it bookmarked in np++ for quick reminders now.

If anyone is interested I'd recommend regex101.com to work on more involved patterns before moving them into np++—its a nice sandbox w/ test text and substitution, as well as a big (but less np++ specific and not entirely beginner friendly) reference library. It also lets you save your patterns if you log in w/ your github(/google/twitter) account or even view other's publicly posted regex examples. The last part I mentioned is great if you're asking how to do basic stuff in comment threads with no answers tbh

Although np++ uses PCRE which is the default flavor on the site I have had a few little issues transferring between them, keeping a list like this in np++ for fixing little differences is advised lol

@shahmustafa

This comment has been minimized.

Copy link

@shahmustafa shahmustafa commented Aug 5, 2017

how to insert set of a sequence number in replacing window?

@rsmolkin

This comment has been minimized.

Copy link

@rsmolkin rsmolkin commented Oct 3, 2017

Hi, I'm trying to run a regex with the global flag, so it would only bring back unique/distinct (last) match of every match. I got some guidance here:
https://stackoverflow.com/questions/46545647/regex-to-find-unique-occurences-of-a-match#46545647
with an example here: https://regex101.com/r/ozFNPV/1

But how do I turn on the g (for global) flag in the Notepad++ search in files Regular Expression search?

@phoenixxko

This comment has been minimized.

Copy link

@phoenixxko phoenixxko commented Nov 12, 2017

dear devs & fans,

I'd like to know if it's possible following:

  1. having a folder, where are multiple files no matter the extension is ...
  2. multi find & replace like:
    if find NAME 1, replace it with NICK1
    if find NAME 2, replace it with NICK2
    ..... up to 400-500 records
  3. so find and replace all matching records with their pairs (pseudonyms) in multiple files at once (including subfolders if possible) ...
    is it possible within notepad++ ? any special plugin or so ?

Many thanks in advance !

@vmsantos

This comment has been minimized.

Copy link

@vmsantos vmsantos commented Dec 1, 2017

Hi.

I want to modify a .sql to change table/column names preffix/suffix. The generated sql uses id as PK suffix. I want to use cod, as a preffix.
So replacing id for cod isn't enough. How would I go about doing that with regex?

@jcuellar15934

This comment has been minimized.

Copy link

@jcuellar15934 jcuellar15934 commented Feb 12, 2018

How can I search for "VCP Address" then include all the number thereafter and stop the search on the last semicolon with no content? Also this would be multiple files.
; VCP Address : 1.2, 1.5, 1.7, 1,9
; 6.215, 5585.5, 4.2
; 3.14, 5.6, 2.5, 8.5
;

@tware667

This comment has been minimized.

Copy link

@tware667 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

This comment has been minimized.

Copy link

@ColinDave ColinDave commented Nov 13, 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.

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

This comment has been minimized.

Copy link

@7thstorm 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

This comment has been minimized.

Copy link

@Vijayakumar144 Vijayakumar144 commented Aug 22, 2019

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

This comment has been minimized.

Copy link

@mgoebel97 mgoebel97 commented Oct 10, 2019

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

This comment has been minimized.

Copy link

@ankushkgarg 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

This comment has been minimized.

Copy link

@Gururajv007 Gururajv007 commented Jan 6, 2020

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

This comment has been minimized.

Copy link

@nadsberces 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

This comment has been minimized.

Copy link

@RajaSurapaneniTR RajaSurapaneniTR commented Apr 2, 2020

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

@Beckfield

This comment has been minimized.

Copy link

@Beckfield 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

This comment has been minimized.

Copy link

@abeypa abeypa commented Jul 7, 2021

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

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