Notepad ++ Find String and place symbol at beginning of line

I have 5000 lines. I need to find if a line contains a certain word phrase such as "package" and put a "1%" at the beginning of it. How would I do this with replace in notepad++?

An example being:

DOGS AND CATS

if the line contains the word "DOGS" anywhere in the string make the new line:

1% DOGS AND CATS


Solution 1:

  • Ctrl+H
  • Find what: ^(?=.*DOGS)
  • Replace with: %1
  • CHECK Match case
  • CHECK Wrap around
  • CHECK Regular expression
  • UNCHECK . matches newline
  • Replace all

Explanation:

^               # beginning of line
(?=.*DOGS)      # positive lookahead, make sure we have DOGS somewhere in the line

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here