I think this is an easy question, but I am not able to find a simple solution (say, less than 10 lines of code 🙂
I have a String such as "thisIsMyString" and I need to convert it to a String[] {"this", "Is", "My", "String"}.
Please notice the first letter is not uppercase.
You may use a regexp with zero-width positive lookahead – it finds uppercase letters but doesn’t include them into delimiter:
Y(?=X)matchesYfollowed byX, but doesn’t includeXinto match. So(?=\\p{Upper})matches an empty sequence followed by a uppercase letter, andsplituses it as a delimiter.See javadoc for more info on Java regexp syntax.
EDIT: By the way, it doesn’t work with
thisIsMyÜberString. For non-ASCII uppercase letters you need a Unicode uppercase character class instead of POSIX one: