title: scala.MatchError: String Extraction using regular expression
body: <p>I am working on scala pattern matching.</p>
  
  <p>For the below program I am getting output.</p>
  
  <pre><code>   val pattern = "([0-9]+) ([A-Za-z]+)".r
  
     val pattern(count,fruit) ="100 bananas"
  </code></pre>
  
  <p>The output of the program is </p>
  
  <p>count: String = 100
  fruit: String = bananas</p>
  
  <p>I modified the program to get deeper understanding, by adding one more numeric pattern into the pattern val object and one more object into the extraction pattern val.</p>
  
  <p>The program is </p>
  
  <pre><code>  val pattern = "([0-9]+) ([A-Za-z]+)  ([0-9]+) ".r
  
    val pattern(count, fruit, price) ="100 bananas 1002"
  </code></pre>
  
  <p>But the program is not compiling and it is throwing error. The error is -</p>
  
  <pre><code>scala.MatchError: 100 bananas 1002 (of class java.lang.String)
  at #worksheet#.x$1$lzycompute(ExtractingStrings.sc0.tmp:6)
  at #worksheet#.x$1(ExtractingStrings.sc0.tmp:6)
  at #worksheet#.count$lzycompute(ExtractingStrings.sc0.tmp:6)
  at #worksheet#.count(ExtractingStrings.sc0.tmp:6)
  at #worksheet#.#worksheet#(ExtractingStrings.sc0.tmp:6)
  </code></pre>
  
  <p>Can anyone explain why it is throwing this error. Thanks in advance.</p>