title: Matching against a regular expression in Scala
body: <p>I fairly frequently match strings against regular expressions.  In Java:</p>
  
  <p>java.util.regex.Pattern.compile("\w+").matcher("this_is").matches</p>
  
  <p>Ouch.  Scala has many alternatives.</p>
  
  <ol>
  <li><code>"\\w+".r.pattern.matcher("this_is").matches</code></li>
  <li><code>"this_is".matches("\\w+")</code></li>
  <li><code>"\\w+".r unapplySeq "this_is" isDefined</code></li>
  <li><code>val R = "\\w+".r; "this_is" match { case R() =&gt; true; case _ =&gt; false}</code></li>
  </ol>
  
  <p>The first is just as heavy-weight as the Java code.</p>
  
  <p>The problem with the second is that you can't supply a compiled pattern (<code>"this_is".matches("\\w+".r")</code>).  (This seems to be an anti-pattern since almost every time there is a method that takes a regex to compile there is an overload that takes a regex).</p>
  
  <p>The problem with the third is that it abuses <code>unapplySeq</code> and thus is cryptic.</p>
  
  <p>The fourth is great when decomposing parts of a regular expression, but is too heavy-weight when you only want a boolean result.</p>
  
  <p>Am I missing an easy way to check for matches against a regular expression?  Is there a reason why <code>String#matches(regex: Regex): Boolean</code> is not defined?  In fact, where is <code>String#matches(uncompiled: String): Boolean</code> defined?</p>