regex - 如何仅在存在定义的前缀的情况下将 CapitalCaseWords 替换为空格大写?

标签 regex notepad++

引用信息: Notepad++ Regex to replace capitalised-case words with space-capital

我需要添加一个要求,即匹配包含定义的前缀。 例如我想替换:

"name": "CapitalCaseWords"
"name": "AnotherStringSentence"
"ThisStringShouldntBeReplaced"

与:

"name": "Capital Case Words"
"name": "Another String Sentence"
"ThisStringShouldntBeReplaced"

在本例中,前缀为 "name": " .

我正在使用(?<=[a-z])(?=[A-Z])但它不适用于前缀。

Regex101 示例:https://regex101.com/r/IpmOnK/2

最佳答案

勾选“匹配大小写”选项后,您可以替换:

("name":\ "[A-Z][a-z]+|(?<!^)\G)([A-Z][a-z]+)

与:

\1 \2

<强> Demo

分割:

(                # Start of 1st capturing group.
    "name":\ "   # Match the prefix (including the double quotation).
    [A-Z][a-z]+  # Match an upper-case letter followed by one or more lower-case letters.
|                # Or:
    (?<!^)\G     # Assert position at the end of the previous match.
)                # End of 1st capturing group.
([A-Z][a-z]+)    # 2nd capturing group matching an upper-case letter followed by 
                 # one or more lower-case letters.

关于regex - 如何仅在存在定义的前缀的情况下将 CapitalCaseWords 替换为空格大写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64602594/

相关文章:

regex - 如何将正则表达式替换中捕获的模式转换为大写?

c - 正则表达式:匹配c中的 float

notepad++ 导出内置语言

Java正则表达式分组问题

javascript - 如何将字符串化的正则表达式文字转换回正则表达式?

python - 如何在 Notepad++ 中缩进一段 Python 代码?

python - Notepad++ 转换为 UTF-8 多个文件

regex - 将空格替换为破折号,但仅限于文本 TAGS =""中引号之间找到的文本

c# - 在 C# 中创建 Notepad++ 插件

javascript - 正则表达式在 javascript 中没有按预期工作