I need to create a regular expression to validate a CamelCase

1

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 ...

    
asked by anonymous 15.09.2016 / 00:58

1 answer

0

Regex: /[A-Z]/g

In this way, you can find all uppercase.

Test

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);
    
15.09.2016 / 01:10