How to match String with Pattern in Groovy
gradle, groovy, match, regex, string
Solution
`(?s)` ignores line breaks for `.*` (DOTALL) and the regexp there means a full match. so with `==~` as shortcut it's:
if ("bla bla errors found:\nhehe Aborting now\n hehe" ==~ /(?s).*errors.*/) ...
Problem
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" ``` task aaa << { 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" } } ```