title: Java Scanner, Pattern and difference between useDelimiter() and skip()
body: <p>What is the difference between <code>java.util.Scanner.useDelimiter()</code> and <code>Scanner.skip()</code> ? For example, I have these strings formatted as shown:</p>
  
  <pre><code>String line1 = "0---20.000:\t\t \t12%";
  String line2 = "0--20.000:\t  12%";
  String line3 = "0-20.000: \t  \t12%";
  String error = "0-: \t\t12%";
  </code></pre>
  
  <p>And I need this output:</p>
  
  <pre><code>0
  20.000
  12
  </code></pre>
  
  <p>I should use a Scanner and a pattern valid for all the three String and I need to control that the tokens are three, otherwise throw an exception. </p>
  
  <p>Could I get this output with both Scanner methods? </p>
  
  <p>And which regex pattern should I use? </p>
  
  <p>It has to be valid also with other numbers.</p>
  
  <p>EDIT: That's my try:</p>
  
  <pre><code>package scanners;
  
  import java.util.Scanner;
  
  public class ScannerTry {
  
  public static void main(String[] args) {
      String line = "0--20.000:       12%";
      Scanner scan = new Scanner(line);
      scan.useDelimiter("[-*:*\t*%]*");
      while (scan.hasNext()){
          System.out.println(scan.next());
      }
      scan.close();
      }
  
  
  }
  </code></pre>
  
  <p>But the output is:</p>
  
  <pre><code>0
  2
  0
  .
  0
  0
  0
  1
  2
  </code></pre>