I’ve got some code splitting a camelCase string into a sentence where each word is separated by a space. That I’ve managed to do using the regex (?=\p{Lu}), but I now also want to exclude a set of camelCase substrings which should kept as they are.
For example, if the words I’m trying to preserve are Class and MultiWordClass, I would want:
containsAClassName -> contains A Class Name
containsAMultiWordClassName -> contains A MultiWordClass Name
(the positions not to match) --> ^ ^
My question is how I can extend that expression to not match positions inside the words I want to preserve. Or possibly, if that is not possible, how I can use a combination of regex and Java to do it. I’ve been trying for some time now, and can’t come up with a solution that works. I’m using Java’s regex-engine.
Here’s a substitution regular expression that you can use for this purpose:
I tried that with Perl, I’m not sure if Java’s regexps are fully compatible with Perl’s — if not, it should be easily adaptable.