title: Pattern matching a domain name
body: <p>I don't use pattern matching as often as I should.
  I am matching a domain name for the following:</p>
  
  <pre><code>1. If it starts with www., then remove that portion and return.
     www.stackoverflow.com =&gt; "stackoverflow.com"
  2. If it has either example.com or example.org, strip that out and return.
     blog.example.com =&gt; "blog"
  3. return request.domain
     hello.world.com =&gt; "hello.world.com"
  
  def filterDomain(request: RequestHeader): String = {
    request.domain match {
      case //?? case #1 =&gt; ?
      case //?? case #2 =&gt; ?
      case _ =&gt; request.domain
    }
  }
  </code></pre>
  
  <p>How do I reference the value (request.domain) inside the expression and see if it starts with "www." like:</p>
  
  <pre><code>if request.domain.startsWith("www.") request.domain.substring(4)
  </code></pre>