title: Java - Reg expression using groups
body: <p>From a string, I need to pull out groups that match a given pattern.</p>
  
  <p>An example string: <code>&lt;XmlLrvs&gt;FIRST&lt;/XmlLrvs&gt;&lt;XmlLrvs&gt;SECOND&lt;/XmlLrvs&gt;&lt;XmlLrvs&gt;Third&lt;/XmlLrvs&gt;</code></p>
  
  <p>Each group shall begin with <code>&lt;XmlLrvs&gt;</code> and end with <code>&lt;/XmlLrvs&gt;</code>. Here is a snippet of my code... </p>
  
  <pre><code>String patternStr = "(&lt;XmlLrvs&gt;.+?&lt;/XmlLrvs&gt;)+";
  
  // Compile and use regular expression
  Pattern pattern = Pattern.compile(patternStr);
  Matcher matcher = pattern.matcher(text);
  matcher.matches();
  
  // Get all groups for this match
  for (int i = 1; i&lt;=matcher.groupCount(); i++) {
     System.out.println(matcher.group(i));
  }
  </code></pre>
  
  <p>The output is <code>&lt;XmlLrvs&gt;Third&lt;/XmlLrvs&gt;</code>. I am expecting group first and second but those aren't being captured. Can anyone assist?</p>