Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you do a Find and Insert in Notepad++ instead of a replace, while using regular expression?

In Notepad++, how do you Find and Insert (instead of Find and Replace) while using a regular expression as the search criteria?

For non regular expression, you can simply include what you are finding in the replace value, but for regular expression, that won't work. Ideas?

like image 539
Thai Truong Avatar asked Mar 02 '12 22:03

Thai Truong


People also ask

How do I Find and replace in Notepad?

Replacing text within NotepadOpen the text file in Notepad. Click Edit on the menu bar, then select Replace in the Edit menu. Once in the Search and Replace window, enter the text you want to find and the text you want to use as a replacement.

How do I use Regular expression in Find and Replace in Notepad++?

Using Regex to find and replace text in Notepad++ In all examples, use select Find and Replace (Ctrl + H) to replace all the matches with the desired string or (no string). And also ensure the 'Regular expression' radio button is set.

How do you remove text before or after a specific character in Notepad++?

Do you want to delete everything before the | and including the | character. You can try find: (. +\|) and leave replace empty.


1 Answers

very simple, if you need to add some text to every match of your search you can use backreferences in regular expressions, so for example, you have:

this is a table.

and you want to get "this is a red table", so you do search for:

(this is a)

and replace with (in regular expression mode):

\1 red

also note, that we've used parenthesis in our search. Each set of parens can be accessed in replace with the corresponding \N tag. So you can, for example search for

(this is).*(table)

and replace it with

\1 not a \2

to get "this is not a table"

like image 132
Dmitry Avtonomov Avatar answered Nov 15 '22 00:11

Dmitry Avtonomov