本文介绍了如何仅在定义的前缀存在的情况下用空格大写替换CapitalCaseWords?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
参考信息: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.
这篇关于如何仅在定义的前缀存在的情况下用空格大写替换CapitalCaseWords?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!