title: Extracting numbers from a String in Java by splitting on a regex
body: <p>I want to extract numbers from Strings like this:</p>
  
  <pre><code>String numbers[] = "M0.286-3.099-0.44c-2.901,-0.436,,,123,0.123,.34".split(PATTERN);
  </code></pre>
  
  <p>From such String I'd like to extract these numbers:</p>
  
  <ul>
  <li>0.286</li>
  <li>-3.099</li>
  <li>-0.44</li>
  <li>-2.901</li>
  <li>-0.436</li>
  <li>123</li>
  <li>0.123</li>
  <li>.34</li>
  </ul>
  
  <p>That is:</p>
  
  <ul>
  <li>There can be garbage characters like "M", "c", "c"</li>
  <li>The "-" sign is to include in the number, not to split on</li>
  <li>A "number" can be anything that <code>Float.parseFloat</code> can parse, so <code>.34</code> is valid</li>
  </ul>
  
  <p>What I have so far:</p>
  
  <pre><code>String PATTERN = "([^\\d.-]+)|(?=-)";
  </code></pre>
  
  <p>Which works to some degree, but obviously far from perfect:</p>
  
  <ul>
  <li>Doesn't skip the starting garbage "M" in the example</li>
  <li>Doesn't handle consecutive garbage, like the <code>,,,</code> in the middle</li>
  </ul>
  
  <p>How to fix PATTERN to make it work?</p>