title: How to match String with Pattern in Groovy
body: <p>I am trying to decide whether a simple regular expression matches a string in Groovy. Here's my task in gradle. I tried to match with 2 different ways I found on the net, but neither of them works. It always prints out "NO ERROR FOUND"</p>
  
  <pre><code>task aaa &lt;&lt; {
      String stdoutStr = "bla bla errors found:\nhehe Aborting now\n hehe"
      println stdoutStr
      Pattern errorPattern = ~/error/
  //  if (errorPattern.matcher(stdoutStr).matches()) {
      if (stdoutStr.matches(errorPattern)) {
          println "ERROR FOUND"
          throw new GradleException("Error in propel: " + stdoutStr)
      } else {
          println "NO ERROR FOUND"
      }
  }
  </code></pre>