Search code examples
regexnotepad++notepad

Comment a line beginning and ending with a pattern


I would like to comment lines beginning with 'echo' and ending with a quote mark '"' :

echo -e "This is my line"

should become :

#echo -e "This is my line"

As I got many lines in my file and as some lines beginning with 'echo' and not ending with a quote mark '"', it's not a simple comment which will solve my problem.

I tried this but it didn't work :

    Find : ^[echo]+["]$
    Replace : #

Solution

  • [echo] is a character class that means 1 character choosen in the class. That's not what you want.

    Use:

    • Ctrl+H
    • Find what: ^\h*echo.+"$
    • Replace with: #$0
    • CHECK Match case
    • CHECK Wrap around
    • CHECK Regular expression
    • UNCHECK . matches newline
    • Replace all