I have a String that I've retrieved from conventions set by get
methods. Something like getMyObject
which becomes MyObject
. I want to make this String presentable to the user so "My Object". However, I also want to account for acronyms that could occur within the object name, so something like getFBILicense
should become "FBI License". I'm a little stuck on how to do this with regex.
(?=\\p{Upper}+\\p{Lower})
The above feels like what I'm after, and yet it's not quite right, this breaks for the simple example "thisIsMMyStringValue" which becomes this
is
M
My
String
Value
. I think this error makes sense to me, as both M
and My
are an uppercase with 0 or more uppercases between them and the first lowercase they encounter. However, I am not sure how to address this using regex so that the returned value is instead this
is
MMy
String
Value
EDIT: I am using Java's String::split
method with the regex in question.