title: java regex: capture multiline sequence between tokens
body: <p>I'm struggling with regex for splitting logs files into log sequence in order to match pattern inside these sequences.
  log format is:</p>
  
  <pre><code>timestamp fieldA fieldB fieldn log message1 
  timestamp fieldA fieldB fieldn log message2
  log message2bis
  timestamp fieldA fieldB fieldn log message3 
  </code></pre>
  
  <p>The timestamp regex is known.</p>
  
  <p>I want to extract every log sequence (potentialy multiline) between timestamps. And I want to keep the timestamp.</p>
  
  <p>I want in the same time to keep the exact count of lines.</p>
  
  <p><strong>What I need is how to decorate timestamp pattern to make it split my log file</strong> in log sequence. I can not split the whole file as a String, since the file <strong>content is provided in a CharBuffer</strong></p>
  
  <p>Here is sample method that will be using this log sequence matcher:</p>
  
  <pre><code>private void matches(File f, CharBuffer cb) {
      Matcher sequenceBreak = sequencePattern.matcher(cb);    // sequence matcher
      int lines = 1;
      int sequences = 0;
  
      while (sequenceBreak.find()) {
          sequences++;
  
          String sequence = sequenceBreak.group();
          if (filter.accept(sequence)) {
              System.out.println(f + ":" + lines + ":" + sequence);                
          }
  
          //count lines
          Matcher lineBreak = LINE_PATTERN.matcher(sequence);
          while (lineBreak.find()) {
              lines++;
          }
  
          if (sequenceBreak.end() == cb.limit()) {
              break;
          }
      }        
  }
  </code></pre>