Search code examples
regexreplacenotepad++

Notepad++: reemplace ocurrences of characters before other character


I have a file with text like this:

"Title" = "Body"

And I would like to remove both " before the =, to leave it like this:

Title = "Body"

So far I managed to select the first block of text with:

.+(=)

That selects everything up to the =, but I can't find how to reemplace (or delete) both " .

Any suggestions?


Solution

  • You could use a capture group in the replacement, and match the double quotes to be removed while asserting an equals sign at the right.

    Find what:

    "([^"]+)"(?=\h*=)
    
    • " Match literally
    • ([^"]+) Capture group 1, match 1+ times any char other than "
    • " Match literally
    • (?=\h*=) Positive lookahead, assert an = sigh at the right

    Regex demo

    Replace with:

    $1
    

    enter image description here


    To match the whole pattern from the start till end end of the string, you might also use 2 capture groups and use those in the replacement.

    ^"([^"]+)"(\h*=\h*"[^"]+")$
    

    Regex demo

    In the replacement use $1$2