How to add spaces between each uppercase letter inside double quotes using Regex in Notepad ++?

Using Regex Find / Replace in Notepad ++, I'm trying to add spaces between each uppercase letter inside double quotes:

.Label("ATextWhichHasCapitalLetters")
.Label(Constants.DefinedLabel)
.Label("AnotherTextWhichHasCapitalLetters")

The result should be:

.Label("A Text Which Has Capital Letters")
.Label(Constants.DefinedLabel)
.Label("Another Text Which Has Capital Letters")

I tried many expressions but could not get the expected result.

Any help would be greatly appreciated.

Thanks.

+4
source share
3 answers

Use an expression other than words \Band look ahead for an uppercase letter to find the insertion points, and the rest of the wait ahead, requiring exactly 1 quotation mark:

Search: \B(?=[A-Z][^"]*"[^"]*$)
Replace: <space>

See the demo .

+1
source
((?<=\w)[A-Z])(?!(?:[^"]*"[^"]*")*[^"]*$)

$1 \1. . .

https://regex101.com/r/iJ7bT6/14

+4

or this template

(?:^[^"]*"|\G)[^"]*?\K(?<![" ])[A-Z]

Demo

+1
source

Source: https://habr.com/ru/post/1624897/


All Articles