title: Scala regex and exact match pattern matching
body: <p>This is string regex question. The requirement is I have some kinds of pattern which is configurable and then this pattern will be used to validate the input information.</p>
  
  <pre><code> val regex = pattern.r
        message match {
          case regex() =&gt; true //this will use exact match
          case regex(t) =&gt; true //this will use regex match
          case _ =&gt; false
   }
  </code></pre>
  
  <p>The implementation about regex() and regex(t) are very similar. I really want to try to unify it. But the reason I am using it is that empty bracket is for exact match and alias with bracket is for regex match.</p>
  
  <pre><code>val pattern = "123(.*)".r
  val exactMatch = "123".r
  
  val t = "123"
  val r = "123123123"
  
  t match {
    case pattern(r) =&gt; println("regex match") //true
    case pattern() =&gt; println("exact match")
  }
  
  r match {
    case pattern(r) =&gt; println("regex match") //true
    case pattern() =&gt; println("exact match")
  }
  
  t match {
    case exactMatch(r) =&gt; println("regex match")
    case exactMatch() =&gt; println("exact match") //true
  }
  
  r match {
    case exactMatch(r) =&gt; println("regex match")
    case exactMatch() =&gt; println("exact match")
    case _ =&gt; //true
  }
  </code></pre>
  
  <p>Is there any better solution ?</p>
  
  <p>Many thanks in advance</p>