Java: Split string when an uppercase letter is found

前端 未结 7 977
醉梦人生
醉梦人生 2020-11-27 15:29

I think this is an easy question, but I am not able to find a simple solution (say, less than 10 lines of code :)

I have a String such as \"thisIs

7条回答
  •  余生分开走
    2020-11-27 15:59

    For anyone that wonders how the Pattern is when the String to split might start with an upper case character:

    String s = "ThisIsMyString";
    String[] r = s.split("(?<=.)(?=\\p{Lu})");
    System.out.println(Arrays.toString(r));
    

    gives: [This, Is, My, String]

提交回复
热议问题