Good morning, everyone, I hope you can help me. I need a regex or even an idea how to insert a space for CamelCase expressions. In other words, insert a space for each capital letter of the word. In java ...
Good morning, everyone, I hope you can help me. I need a regex or even an idea how to insert a space for CamelCase expressions. In other words, insert a space for each capital letter of the word. In java ...
Regex: /[A-Z]/g
In this way, you can find all uppercase.
So in the code you can use something like:
String s = "TudoMaiúsculoSemEspaçoQuemFezIsso";
StringBuilder out = new StringBuilder(s);
Pattern p = Pattern.compile("[A-Z]");
Matcher m = p.matcher(s);
int extraFeed = 0;
while(m.find()){
if(m.start()!=0){
out = out.insert(m.start()+extraFeed, " ");
extraFeed++;
}
}
System.out.println(out);