title: JavaScript split string by regex
body: <p>I will have a string never long than 8 characters in length, e.g.:</p>
  
  <pre><code>// represented as array to demonstrate multiple examples
  var strs = [
      '11111111',
      '1RBN4',
      '12B5'
  ]    
  </code></pre>
  
  <p>When ran through a function, I would like all digit characters to be summed to return a final string:</p>
  
  <pre><code>var strsAfterFunction = [
      '8',
      '1RBN4',
      '3B5'
  ]
  </code></pre>
  
  <p>Where you can see all of the 8 single <code>1</code> characters in the first string end up as a single <code>8</code> character string, the second string remains unchanged as at no point are there adjacent digit characters and the third string changes as the <code>1</code> and <code>2</code> characters become a <code>3</code> and the rest of the string is unchanged.</p>
  
  <p>I believe the best way to do this, in pseudo-code, would be:</p>
  
  <pre><code>1. split the array by regex to find multiple digit characters that are adjacent
  2. if an item in the split array contains digits, add them together
  3. join the split array items
  </code></pre>
  
  <p>What would be the <code>.split</code> regex to split by multiple adajcent digit characters, e.g.:</p>
  
  <pre><code>var str = '12RB1N1'
    =&gt; ['12', 'R', 'B', '1', 'N', '1']
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>question:
  What about the string "999" should the result be "27", or "9"</p>
  
  <p>If it was clear, always SUM the digits, <code>999</code> => <code>27</code>, <code>234</code> => <code>9</code></p>