1
Good morning to everyone, I hope you can help me. I need a regex or even an idea of how to insert a space for Camelcase expressions. In other words, insert a space for each uppercase letter of the word. Java...
1
Good morning to everyone, I hope you can help me. I need a regex or even an idea of how to insert a space for Camelcase expressions. In other words, insert a space for each uppercase letter of the word. Java...
0
Regex : /[A-Z]/g
This way you can find all the uppercase.
So in 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);
Browser other questions tagged java regex
You are not signed in. Login or sign up in order to post.
Why did you use Matcher and Pattern?
– Stan
And Thanks worked here for me, I just wanted an explanation for having used the two classes q I quoted Matcher and Pattern
– Stan
@Stan https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html
– MagicHat