title: Scala regex pattern match of ip address
body: <p>I can't understand why this code returns false:</p>
  
  <pre><code>      val reg = """.*(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}).*""".r
        "ttt20.30.4.140ttt" match{
          case reg(one, two, three, four) =&gt;
            if (host == one + "." + two + "." + three + "." + four) true else false
          case _ =&gt; false
        }
  </code></pre>
  
  <p>and only if I change it to:</p>
  
  <pre><code>  val reg = """.*(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}).*""".r
    "20.30.4.140" match{
      case reg(one, two, three, four) =&gt;
        if (host == one + "." + two + "." + three + "." + four) true else false
      case _ =&gt; false
    }
  </code></pre>
  
  <p>it does match</p>