title: Java regex capture EOL, regex over stream
body: <p>I'm trying to implement regex over stream (Reader). I'm using the following approach:</p>
  
  <ol>
  <li>Read N chars to buffer</li>
  <li>Call matcher.find() on this buffer</li>
  <li>Trim from the beginning till matcher.end() position and append buffer to N chars length</li>
  <li>Loop</li>
  </ol>
  
  <p>There is an issue with regex ^(.*)$ (it is user data and it is not possible to change it). The matcher did not capture line endings, so matcher.end() returns last symbol before \n char not the \n itself. And after that program loops in empty string. E.g. we have input "ABC\nCDE"</p>
  
  <ul>
  <li>matcher captures ABC and matcher.end() returns 2</li>
  <li>substring(2) returns "\nCDE"</li>
  <li>matcher captures empty string and loops here</li>
  </ul>
  
  <p>Is there is any way to make mather include EOL chars into capturing group? Or there is regex implementations for Java that work with streams?</p>
  
  <p>P.S. There is one solution but it is very ugly, I do not wont to implement it:</p>
  
  <pre><code>String text = "ABC\r\nDEF\r\nGHI\r\n";
  Pattern pattern = Pattern.compile("^(.*)$", Pattern.MULTILINE);
  boolean first = true;
  Matcher matcher = pattern.matcher(text);
  while (matcher.find(first ? 0 : 1)) {
      System.out.println(matcher.group());
      text = text.substring(matcher.end() - 1);
      matcher.reset(text);
      first = false;
  }
  </code></pre>