Search code examples
regexreplacenotepad++

Notepad++ all instances of character under a condition


This is my text

BROKEN This is a "sentence".
This sentence is an actual normal sentence.

I wish to replace/filter the quotation marks out of every line that has the word BROKEN in it I thought this would be simple but I couldn't do it my regex

(?=BROKEN)"

could I get some help?


Solution

  • If you also want to match double quotes before the word BROKEN, you can skip the whole line that does not contain the word.

    Find what:

    ^(?!.*\bBROKEN\b).*\R?(*SKIP)(*F)|"
    

    Replace with: (leave empty)

    Explanation

    • ^ Start of string
    • (?!.*\bBROKEN\b) Negative lookahead, assert that the word BROKEN does not occur
    • .*\R?(*SKIP)(*F) Match the whole line including an optional newline and skip the match
    • | Or
    • " Match a double quote

    See a regex101 demo.

    Before

    enter image description here

    After

    enter image description here