title: How to do CamelCase split in python
body: <p>What I was trying to achieve, was something like this:</p>
  <pre><code>&gt;&gt;&gt; camel_case_split(&quot;CamelCaseXYZ&quot;)
  ['Camel', 'Case', 'XYZ']
  &gt;&gt;&gt; camel_case_split(&quot;XYZCamelCase&quot;)
  ['XYZ', 'Camel', 'Case']
  </code></pre>
  <p>So I searched and found this <a href="https://stackoverflow.com/a/7599674/1654255">perfect regular expression</a>:</p>
  <pre><code>(?&lt;=[a-z])(?=[A-Z])|(?&lt;=[A-Z])(?=[A-Z][a-z])
  </code></pre>
  <p>As the next logical step I tried:</p>
  <pre><code>&gt;&gt;&gt; re.split(&quot;(?&lt;=[a-z])(?=[A-Z])|(?&lt;=[A-Z])(?=[A-Z][a-z])&quot;, &quot;CamelCaseXYZ&quot;)
  ['CamelCaseXYZ']
  </code></pre>
  <p>Why does this not work, and how do I achieve the result from the linked question in python?</p>
  <p><strong>Edit: Solution summary</strong></p>
  <p>I tested all provided solutions with a few test cases:</p>
  <pre class="lang-none prettyprint-override"><code>string:                 ''
  AplusKminus:            ['']
  casimir_et_hippolyte:   []
  two_hundred_success:    []
  kalefranz:              string index out of range # with modification: either [] or ['']
  
  string:                 ' '
  AplusKminus:            [' ']
  casimir_et_hippolyte:   []
  two_hundred_success:    [' ']
  kalefranz:              [' ']
  
  string:                 'lower'
  all algorithms:         ['lower']
  
  string:                 'UPPER'
  all algorithms:         ['UPPER']
  
  string:                 'Initial'
  all algorithms:         ['Initial']
  
  string:                 'dromedaryCase'
  AplusKminus:            ['dromedary', 'Case']
  casimir_et_hippolyte:   ['dromedary', 'Case']
  two_hundred_success:    ['dromedary', 'Case']
  kalefranz:              ['Dromedary', 'Case'] # with modification: ['dromedary', 'Case']
  
  string:                 'CamelCase'
  all algorithms:         ['Camel', 'Case']
  
  string:                 'ABCWordDEF'
  AplusKminus:            ['ABC', 'Word', 'DEF']
  casimir_et_hippolyte:   ['ABC', 'Word', 'DEF']
  two_hundred_success:    ['ABC', 'Word', 'DEF']
  kalefranz:              ['ABCWord', 'DEF']
  </code></pre>
  <p>In summary you could say the solution by @kalefranz does not match the question (see the last case) and the solution by @casimir et hippolyte eats a single space, and thereby violates the idea that a split should not change the individual parts. The only difference among the remaining two alternatives is that my solution returns a list with the empty string on an empty string input and the solution by @200_success returns an empty list.
  I don't know how the python community stands on that issue, so I say: I am fine with either one. And since 200_success's solution is simpler, I accepted it as the correct answer.</p>