title: Java: I have a big string of html and need to extract the href="..." text
body: <p>I have this string containing a large chunk of html and am trying to extract the link from href="..." portion of the string. The href could be in one of the following forms:</p>
  
  <pre><code>&lt;a href="..." /&gt;
  &lt;a class="..." href="..." /&gt;
  </code></pre>
  
  <p>I don't really have a problem with regex but for some reason when I use the following code:</p>
  
  <pre><code>        String innerHTML = getHTML(); 
    Pattern p = Pattern.compile("href=\"(.*)\"", Pattern.DOTALL);
    Matcher m = p.matcher(innerHTML);
    if (m.find()) {
     // Get all groups for this match
     for (int i=0; i&lt;=m.groupCount(); i++) {
      String groupStr = m.group(i);
      System.out.println(groupStr);
  
     }
    }
  </code></pre>
  
  <p>Can someone tell me what is wrong with my code? I did this stuff in php but in Java I am somehow doing something wrong... What is happening is that it prints the whole html string whenever I try to print it...</p>
  
  <p>EDIT: Just so that everyone knows what kind of a string I am dealing with:</p>
  
  <pre><code>&lt;a class="Wrap" href="item.php?id=43241"&gt;&lt;input type="button"&gt;
      &lt;span class="chevron"&gt;&lt;/span&gt;
    &lt;/a&gt;
    &lt;div class="menu"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Everytime I run the code, it prints the whole string... That's the problem...</p>
  
  <p>And about using jTidy... I'm on it but it would be interesting to know what went wrong in this case as well...</p>