title: How to find all possible regex matches
body: <p>Is there a way to get all possible match using regex in java :</p>
  
  <p>Java Tester Program :</p>
  
  <pre><code> public class NewClass {
           public static void main(String[] args) throws IOException {
              String targetFileStr = IOUtils.toString(new FileInputStream(new File("src/SampleHTML.html")), "UTF-8");
              Matcher matcher = Pattern.compile("&lt;body&gt;(.|[\\r\\n])*?&lt;link").matcher(targetFileStr);
              while (matcher.find()) {
                  System.out.println(matcher.group());
              }
          }
      }
  </code></pre>
  
  <p>Sample HTML File like :</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;body&gt;
          &lt;script src="1"&gt;&lt;/script&gt;
          &lt;link href="1" /&gt;
          &lt;link href="2" /&gt;
          &lt;link href="3" /&gt;
          &lt;div&gt;TODO write content&lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Non-Greedy Regex Current Output : Current Output of program is give below in case of non-greedy regex - <code>"&lt;body&gt;(.|[\\r\\n])*&lt;link"</code> </p>
  
  <pre><code>&lt;body&gt;
          &lt;script src="1"&gt;&lt;/script&gt;
         &lt;link
  </code></pre>
  
  <p>Greedy Regex Current Output : Current Output of program is give below in case of greedy regex - <code>"&lt;body&gt;(.|[\\r\\n])*?&lt;link"</code> </p>
  
  <pre><code>&lt;body&gt;
              &lt;script src="1"&gt;&lt;/script&gt;
              &lt;link href="1" /&gt;
              &lt;link href="2" /&gt;
              &lt;link
  </code></pre>
  
  <p>Expected Output : But i need to get all possible match from body to link</p>
  
  <pre><code>  1:   &lt;body&gt;
              &lt;script src="1"&gt;&lt;/script&gt;
             &lt;link
  
    2:   &lt;body&gt;
              &lt;script src="1"&gt;&lt;/script&gt;
              &lt;link href="1" /&gt;
              &lt;link
  
    3:   &lt;body&gt;
              &lt;script src="1"&gt;&lt;/script&gt;
              &lt;link href="1" /&gt;
              &lt;link href="2" /&gt;
              &lt;link
  </code></pre>
  
  <p>Why this Question : I am creating tool that will find and highlight all external style sheet in body .</p>