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.

avinav597 commented Mar 12, 2016

How to make the program replace only in selected region.

@eproffitt

This comment has been minimized.

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.

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.

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.

HatemHusam commented Sep 6, 2016

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

@bhushanbaviskar

This comment has been minimized.

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.

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.

sverremb commented Jan 6, 2017

To replace a blank line, use \n\r

@lukegaylor

This comment has been minimized.

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.

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.

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.

shahmustafa commented Aug 5, 2017

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

@rsmolkin

This comment has been minimized.

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.

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.

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.

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.

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.

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)

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