maro01507
maro01507

Reputation: 13

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?

Upvotes: 0

Views: 59

Answers (2)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626893

You can use

(?:\G(?!^)|^(?=.*=))[^"=\v]*\K"

Replace with an empty string.

Details:

  • (?:\G(?!^)|^(?=.*=)) - end of the previous successful match (\G(?!^)) or (|) start of a line that contains = somewhere on it (^(?=.*=))
  • [^"=\v]* - any zero or more chars other than ", = and vertical whitespace
  • \K - omit the text matched
  • " - a " char (matched, consumed and removed)

See the screenshot with settings and a demo:

enter image description here

Upvotes: 0

The fourth bird
The fourth bird

Reputation: 163362

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

Upvotes: 1

Related Questions