title: Java regex capturing groups indexes
body: <p>I have the following line,</p>
  
  <pre><code>typeName="ABC:xxxxx;";
  </code></pre>
  
  <p>I need to fetch the word <code>ABC</code>, </p>
  
  <p>I wrote the following code snippet,</p>
  
  <pre><code>Pattern pattern4=Pattern.compile("(.*):");
  matcher=pattern4.matcher(typeName);
  
  String nameStr="";
  if(matcher.find())
  {
      nameStr=matcher.group(1);
  
  }
  </code></pre>
  
  <p>So if I put <code>group(0)</code> I get <code>ABC:</code> but if I put <code>group(1)</code> it is <code>ABC</code>, so I want to know </p>
  
  <ol>
  <li><p>What does this <code>0</code> and <code>1</code> mean? It will be better if anyone can explain me with good examples. </p></li>
  <li><p>The regex pattern contains a <code>:</code> in it, so why <code>group(1)</code> result omits that? Does group 1 detects all the words inside the parenthesis? </p></li>
  <li><p>So, if I put two more parenthesis such as, <code>\\s*(\d*)(.*)</code>: then, will be there two groups? <code>group(1)</code> will return the <code>(\d*)</code> part and <code>group(2)</code> return the <code>(.*)</code> part?</p></li>
  </ol>
  
  <p>The code snippet was given in a purpose to clear my confusions. It is not the code I am dealing with. The code given above can be done with <code>String.split()</code> in a much easier way.</p>