RegEx to splitt camelCase or TitleCase (advanced)
I found a [brilliant RegEx][1] to extract the part of a camelCase or TitleCase expression.

     (?<!^)(?=[A-Z])

It works as expected:

 - value -> value
 - camelValue -> camel / Value
 - TitleValue -> Title / Value

For example with Java:

<!-- language: lang-java -->

    String s = "loremIpsum";
    words = s.split("(?&#60;!^)(?=[A-Z])");
    //words equals words = new String[]{"LOREM","IPSUM"}

My problem is that it does not work in some cases:

- Case 1: VALUE -> V / A / L / U / E
- Case 2: eclipseRCPExt -> eclipse / R / C / P / Ext

To my mind, the result shoud be:

- Case 1: VALUE
- Case 2: eclipse / RCP / Ext

In other words, given n uppercase chars:

- if the n chars are followed by lower case chars, the groups should be: (n-1 chars) / (n-th char + lower chars)
- if the n chars are at the end, the group should be: (n chars).

Any idea on how to improve this regex?


  [1]: http://jason.diamond.name/weblog/2009/08/15/splitting-camelcase-with-regular-expressions/
RegEx to splitt camelCase or TitleCase (advanced)
===

I found a [brilliant RegEx][1] to extract the part of a camelCase or TitleCase expression.

     (?<!^)(?=[A-Z])

It works as expected:

 - value -> value
 - camelValue -> camel / Value
 - TitleValue -> Title / Value

For example with Java:

<!-- language: lang-java -->

    String s = "loremIpsum";
    words = s.split("(?&#60;!^)(?=[A-Z])");
    //words equals words = new String[]{"LOREM","IPSUM"}

My problem is that it does not work in some cases:

- Case 1: VALUE -> V / A / L / U / E
- Case 2: eclipseRCPExt -> eclipse / R / C / P / Ext

To my mind, the result shoud be:

- Case 1: VALUE
- Case 2: eclipse / RCP / Ext

In other words, given n uppercase chars:

- if the n chars are followed by lower case chars, the groups should be: (n-1 chars) / (n-th char + lower chars)
- if the n chars are at the end, the group should be: (n chars).

Any idea on how to improve this regex?


  [1]: http://jason.diamond.name/weblog/2009/08/15/splitting-camelcase-with-regular-expressions/