How to find and replace line(s) in multiple files using Notepad++

findfind and replacenotepad

I have been messing with notepad++ for a bit now and am confused as to how to go about doing this:

I have a line in multiple files (Within a root directory) that I am searching for. Example:

Brittany (File 1)
     PeopleSleptWith 2
Tiffany (File 2)
     PeopleSleptWith 4
Bonqueesh (File 3)
     PeopleSleptWith 3456
.
.
.

My goal is to replace all of the PeopleSleptWith lines with a constant (I.E. PeopleSleptWith 7) but when I search and replace in multiple files, it does not remove complete line, which results in:

Brittany (File 1)
     PeopleSleptWith 7 2
Tiffany (File 2)
     PeopleSleptWith 7 4
Bonqueesh (File 3)
     PeopleSleptWith 7 3456

When in reality I want:

Brittany (File 1)
     PeopleSleptWith 7
Tiffany (File 2)
     PeopleSleptWith 7
Bonqueesh (File 3)
     PeopleSleptWith 7

So how do i go on about finding a string, removing everything within that line, and replacing it with another string?

Best Answer

Using Notepad++ to find a string on a line in a file, and replace that entire line with the match with another string

Instructions

Open Notepad++ and press Ctrl+F and then from the Find in Files tab options.

Now you'll...

  1. Put the string in the regex format of the Find What: ^.*(PeopleSleptWith).*$

    • The string will go between the "()" parenthesis just as shown above in #1
  2. Put the 5 spaces and then the Replace with: PeopleSleptWith 7 string

  3. Put the Filters: as *.* or *.txt or whatever you are replacing file type wise
  4. Put the Directory: where you want it to be (the root folder)
  5. Check the Regular expression option
  6. Select Replace in Files
  7. Check the file(s) and all should be correct now

    enter image description here