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

3

5

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?

Sirrah answered 2/3, 2012 at 22:58 Comment(0)
H
7

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"

Hirsh answered 2/3, 2012 at 23:9 Comment(0)
G
2

Dmitry Avtonomov answered it right but I just wanted to add in case you have something dynamic in between two strings.

Example:

Line 1: Question 1

Line 2: Question 2

And you want to just add a dot after the end of each question number, you can add at this way.

In Notepad++

Replace : (QUESTION)(.*)(\r\n)
With : \1 \2. \3

Result:

Line 1: Question 1.

Line 2: Question 2.

Garrek answered 5/4, 2018 at 14:33 Comment(0)
C
-1

Have you checked other posts?

Maybe this will help you get your answers:

Using regular expressions to do mass replace in Notepad++ and Vim http://markantoniou.blogspot.com/2008/06/notepad-how-to-use-regular-expressions.html

Copper answered 2/3, 2012 at 23:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.