title: Java - Possible to Remove all Characters except '.' and numbers for double/floats?
body: <p>There is a small problem I am trying to solve, it is a part of code that basically checks versions against versions on other machines via version files. It looks at the names of these files, and strips all characters currently.</p>
  
  <p>At first, I tried:</p>
  
  <pre><code>private String getLatestVerFile( List&lt;String&gt; verFiles ) {
  
      String latestVerFile = null;
      long lastMod = Long.MIN_VALUE;
  
      for (String file : verFiles ) {
  
          if ( Long.parseLong( file.replaceAll( "[^0-9]", "" ) ) &gt; lastMod ) {
              latestVerFile = file;
              lastMod = Long.parseLong( file.replaceAll( "[^0-9]", "" ) );
          }
      }
  
      return latestVerFile;       
  }
  </code></pre>
  
  <p>The problem here is given multiple version files, it is meant to return the latest one, and it won't in some cases:</p>
  
  <pre><code>ex:
  R9.10 = 910
  R9.26_P1 = 9261
  R9.01 = 901
  R10.1 = 101
  </code></pre>
  
  <p>In this case, R10.1 would be the latest version.</p>
  
  <p>Personally I would like for them to adopt a more standard and straightforward release numbering scheme, but that's out of my control.</p>
  
  <p>My idea was to try handling this as a double. I thought you could use [^0-9.] per some Google searching, as seen below.</p>
  
  <pre><code>private String getLatestVerFile( List&lt;String&gt; verFiles ) {
  
      String latestVerFile = null;
      double lastMod = Double.MIN_VALUE;
  
      for (String file : verFiles ) {
  
          if ( Double.parseDouble( file.replaceAll( "[^0-9.]", "" ) ) &gt; lastMod ) {
              latestVerFile = file;
              lastMod = Double.parseDouble( file.replaceAll( "[^0-9.]", "" ) );
          }
      }
  
      return latestVerFile;       
  }
  </code></pre>
  
  <p>That said, it doesn't work. I think what may be throwing this off is the fact the filename is R9.10.ver, for example, and it's possibly coming out as "9.10." and trying to make that a double. A coworker said to use R(\d+.\d+)(_P\d+1).ver, but I don't know where to begin with all of that, or how it would know what to filter out of the string.</p>
  
  <p>The goal is to get this:</p>
  
  <pre><code>ex:
  R9.10 = 9.10
  R9.20_P1 = 9.201
  R10.11 = 10.11
  R10.20_P1 = 10.201
  </code></pre>
  
  <p>But I'm especially stuck on how I can get this done. Advice? I guess part of my problem is I'm honestly not understanding regular expressions all that well, and how to choose what parts to ignore of the pattern.</p>