title: java.lang.IndexOutOfBoundsException: No group 1 | Pattern matching
body: <p>I am trying to extract the value of version from <code>Accept</code> header which can be of the form</p>
  
  <pre><code>"vnd.example-com.foo+json; version=1.1" 
  </code></pre>
  
  <p>here is my code for extracting the version</p>
  
  <pre><code>val resourceVersionPattern: Pattern = Pattern.compile("(?&lt;=version=).*")
  
  def getResourceVersion(acceptHeader: String): String = {
              import java.util.regex.Matcher
              val matcher: Matcher = resourceVersionPattern.matcher(acceptHeader)
              if(matcher.find()) ("v" + matcher.group(1)).trim() else "v1.0"
      }
  </code></pre>
  
  <p>When I am invoking the above function which is intended to extract version (for example can be of the form v1.0 or v1.5 or v2.5) </p>
  
  <pre><code> getResourceVersion("vnd.example-com.foo+json; version=1.1")
  </code></pre>
  
  <p>I get following exception:</p>
  
  <pre><code>java.lang.IndexOutOfBoundsException: No group 1
  at java.util.regex.Matcher.group(Matcher.java:487)
  at .getResourceVersion(&lt;console&gt;:12)
  at .&lt;init&gt;(&lt;console&gt;:11)
  at .&lt;clinit&gt;(&lt;console&gt;)
  at .&lt;init&gt;(&lt;console&gt;:11)
  at .&lt;clinit&gt;(&lt;console&gt;)
  at $print(&lt;console&gt;)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704)
  at scala.tools.nsc.interpreter.IMain$Request$$anonfun$14.apply(IMain.scala:920)
  at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:43)
  at scala.tools.nsc.io.package$$anon$2.run(package.scala:25)
  at java.lang.Thread.run(Thread.java:744)
  </code></pre>
  
  <p>I think I am doing something wrong in my regex or the input string has some illegal charecters which I am not able to identify with my limited knowledge of Regular expression. Help me find out the reason.</p>