如何仅在存在已定义前缀的情况下用 space-capital 替换 CapitalCaseWords?

How to replace CapitalCaseWords with space-capital only where a defined prefix exists?

参考信息:

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

"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]+)

与:

 

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.