I try to write a regular expression in order to:
I have the text: ClassNameOne839
, and I want to get the text: Class Name One
There is a library function which do it? or any regular expression?
You can use a combination of replaceAll()
calls like this:
String text = "ClassNameOne839";
String cleanText = text.replaceAll("\\d+", "").replaceAll("(.)([A-Z])", "$1 $2");
This first removes all numbers, and then adds a space before all upper-case letters that are not at the beginning of the String
. $1
and $2
are references to the first and second groups of the regex.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With