I'm trying to use regex and notepad++ to convert "CapitalCaseWords" with "Capital Case Words" I stole a regex from the answer here which does what I need, but I don't know how to convert it into find and replace versions for use in npp...
Asked
Active
Viewed 121 times
1 Answers
1
You could try replacing with the following lookarounds:
Find: (?<=[a-z])(?=[A-Z])
Replace: (single space)

Tim Biegeleisen
- 502,043
- 27
- 286
- 360
-
When I try in notepad++ I get this result:CapitalCaseWords ==> C a p i t a l C a s e W o r d s – njminchin Oct 30 '20 at 03:51
-
1That's probably because you are doing a case-insensitive regex replacement. It needs to be case sensitive. – Tim Biegeleisen Oct 30 '20 at 03:52
-
@Applez00800 Tick the `Match case` checkbox. – 41686d6564 stands w. Palestine Oct 30 '20 at 03:53
-
Thanks, that works. What if I want to add a prefix to it, so that only text with the prefix are replaced? e.g. Alm_CapitalCaseWords ==> Alm_Capital Case Words – njminchin Oct 30 '20 at 03:56
-
1That requirement is much trickier than what you asked (though it might be a logical follow-up for you). Typically, we would handle it in a programming language by using a regex callback. First, we would match `\bAlm_\S+`. Then, we would pass each match to a callback function, and there use my current regex answer. – Tim Biegeleisen Oct 30 '20 at 03:57
-
@Applez00800 You may replace `(?:Alm_[A-Z][a-z]+|(?<!^)\G)\K([A-Z][a-z]+)` with " \1". [Demo](https://regex101.com/r/gWRyl2/1). Or maybe `(Alm_[A-Z][a-z]+|(?<!^)\G)([A-Z][a-z]+)` with `\1 \2`. – 41686d6564 stands w. Palestine Oct 30 '20 at 04:07
-
@41686d6564 Why don't you post this as answer in [this follow-up question](https://stackoverflow.com/questions/64602594/regex-notepad-to-replace-capitalcasewords-with-space-capital-only-where-a-defi) ? – Tim Biegeleisen Oct 30 '20 at 04:08