title: Scala Regex Pattern Match not able to get it to work
body: <p>I am trying to write a regex for having string separated by dots. For example,</p>
  
  <pre><code>"abc", "abc.def", "a.b.c.e.f" 
  </code></pre>
  
  <p>are all valid, but</p>
  
  <pre><code>"abc..def", ".abc", "abc." 
  </code></pre>
  
  <p>are not valid</p>
  
  <p>Here is my regex code in scala </p>
  
  <pre><code>object Test {
    def main(args: Array[String]) {
  
      val TestPattern = "^([a-z]+)(\\.?[a-z]+)*".r
      val x: String = "abc.def.hij"
  
      x match {
        case TestPattern(a,b) =&gt; println(a + b)
        case _ =&gt; println("Not Found")
      }
    }
  }
  </code></pre>
  
  <p>So here is my regex,</p>
  
  <pre><code>"^([a-z]+)(\\.?[a-z]+)*".r
  </code></pre>
  
  <p>which has two components,</p>
  
  <pre><code>1. Starts with a-z
  2. Repeat (has 0 or 1 dot, one or more from a-z) zero or more times
  </code></pre>
  
  <p>But, </p>
  
  <pre><code>Input: abc.def.hij
  Output: abc.hij
  </code></pre>
  
  <p>I don't understand why </p>
  
  <pre><code>.def
  </code></pre>
  
  <p>doesn't show up in my output. </p>