title: Include delimiter in token when using Scanner in Java
body: <p>I want to use Java Scanner object to read file line "blocks" into objects.  The delimiter needs to be included in token.  I tried using regex lookbehind, but delimitter is variable length.  Does anyone have suggestions or alternatives for getting the delimiter?</p>
  
  <p>Java code I currently have (which erroneously removes the "Processed Value" line):</p>
  
  <pre><code>ArrayList&lt;ProcessedData&gt; stack = new ArrayList&lt;ProcessedData&gt;();    
  
  Scanner scanner = new Scanner(new File("/home/user/data.txt"));
  Pattern pattern = Pattern.compile("Processed Value.+?\\n+", Pattern.UNIX_LINES);
  scanner.useDelimiter(pattern);
  
  while(scanner.hasNext()) {
      stack.add(new ProcessedData(scanner.next()));
  }
  </code></pre>
  
  <p>Example file:</p>
  
  <pre><code>Id: 1
  Raw Value: 1234
  Processed Value{423}: A3s2344
  
  Id: 36
  Raw Value: 389001
  Processed Value{2}: "Access Success"
  
  Id: 28934
  Raw Value: 2402
  Processed Value: 1345.2 seconds
  </code></pre>