i am looking for GREP help. I have an issue where i need to delete every line that contains [DELETELINE].

So that

Test [DELETELINE] loremipsum
[DELETELINE] loremipsum
loremipsum [DELETELINE]



I only can get parts of it to work. Like delete the line if [DELETELINE] is in the middle or in the beginning or at the end. But i need an expression that catches all cases.

Is that possible?


What i got is this:


But this selects only the third line.


1 Answer 1


I think i found the answer

the following grep works for all cases


^ is beginning of a paragraph \r and \n are different types of linebreaks so everything should be catched.

  • 1
    With this query, if your last line must be deleted, it wouldn't be caught because there would be no vertical space at the end of it. Try .*[DELETELINE].*\v? in order to catch it as well. FYI \v means vertical space (it catches both \r and \n) and ? means zero or one time
    – Vinny
    Jan 8, 2018 at 8:39
  • Your recommendation targets every line. Also those two i don't want to touch. But the ? was a good hint. With that my solution works. + 1
    – Pat_Morita
    Jan 8, 2018 at 9:35
  • Oh I see... the anti-slashes before the brackets were deleted in my comment. Just type them back ^^
    – Vinny
    Jan 8, 2018 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.