title: Got Exception in thread "main" java.lang.IndexOutOfBoundsException: No group 1
body: <p>I have a string like this</p>
  
  <pre><code>"abc:def"
  </code></pre>
  
  <p>I need to check if it matches. If yes, I want to apply a regex and retrieve first part of it (<code>"abc"</code>).</p>
  
  <p>Here is my try:</p>
  
  <pre><code>Pattern pattern = Pattern.compile(".*:.*");
  String  name = "abc:def"
  Matcher matcher = pattern.matcher(name);
  
  if (matcher.find()) {
      String group = matcher.group(1);
      System.out.println(group);
  }
  </code></pre>
  
  <p>It gives me </p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.IndexOutOfBoundsException: No group 1</p>
  </blockquote>