引用信息: 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/