2

Reference info: Notepad++ Regex to replace capitalised-case words with space-capital

I need to add to this a requirement that the match contains a defined prefix. For example I want to replace:

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

with:

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

Where the prefix, in this case, is "name": ".

I'm using (?<=[a-z])(?=[A-Z]) but it's not working for prefix.

Regex101 example: https://regex101.com/r/IpmOnK/2

njminchin
  • 408
  • 3
  • 13

1 Answers1

4

With the "Match case" option ticked, you may replace:

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

With:

\1 \2

Demo.

Breakdown:

(                # 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.