如何在 Notepad++ 中使用正则表达式在双引号内的每个大写字母之间添加空格?

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

在 Notepad++ 中使用正则表达式 Find/Replace,我试图在双引号内的每个大写字母之间添加空格:

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

结果应该是:

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

我尝试了很多表达式,但没有得到预期的结果。

如有任何帮助,我们将不胜感激。

谢谢。

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

您可以使用它并替换为 </code> 或 <code>。参见演示。

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

或者这个模式

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

Demo

使用 non-word-boundary 表达式 \B 和一个大写字母的前瞻来找到插入点,其余的前瞻需要恰好 1 个引号如下:

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

参见demo