title: Android - How can I replace the number in this type of string?
body: <p>does anyone know how can I replace the number in this type of string and delete the second part (if exists)?</p>
  
  <p>I know this sound weird, let me explain.</p>
  
  <p>The string to deal with is different each time:</p>
  
  <p>The number (what I need to replace) can be from <code>1</code> digit up to <code>10</code> digits, from: <code>0</code> up to: <code>9999999999</code> (also could be zeros <code>0000000000</code>).</p>
  
  <p>Always has a character before the number (could be any character, any case), like: <code>X0000</code>, <code>a00</code>, <code>h000000</code>, <code>G000</code>.</p>
  
  <p>Sometimes might have another part following it (starts with a hyphen, I need to remove this part if exists), like: <code>X000-X00000</code>, <code>X0000-X00</code>, <code>X00-X0</code>.</p>
  
  <p>Sometimes might have another extra character following it (could be any character, any case, starts with a hyphen, I need to keep this part if exists), like: <code>X00000-X</code>, <code>X0000-X000-X</code>, <code>a000-h</code>, <code>g00000-j00-Y</code>.</p>
  
  <p>I don't know how to replace the first part (if exists), delete the second part (if exists) and keep the last part (if exists), this is an example of what I need:</p>
  
  <pre><code>X0000 &gt; X1234
  a00 &gt; a12
  h000000 &gt; h123456
  G000 &gt; G123
  
  X000-X000000 &gt; X123  -  replace the first and delete the last
  X0000-X000 &gt; X1234 -  replace the first and delete the last
  X00-X00 &gt; X12 -  replace the first and delete the last
  
  X00000-X &gt; X12345-X -  replace only the first and keep the last
  a000-h &gt; a123-h -  replace it and keep the last
  
  X0000-X000-X &gt; X1234-X -  replace the first, delete the second and keep the last
  g00000-j00-Y &gt; g12345-Y -  replace the first, delete the second and keep the last
  </code></pre>
  
  <p>In this examples I used 0 and X mostly, but like explained, could be 0 or any number and could be X or any character (capital or lowercase).</p>
  
  <p>EDIT: forgot to mention, I need to get that number, do a math with it and then replace it, is not just replacing.</p>
  
  <p>Does anyone know how to do it? Thanks a lot.</p>