Groovy supports regular expressions natively using the ~"..." expression. Plus Groovy supports the =~ (create Matcher) and ==~ (matches regex) operators. e.g.
Error rendering macro 'code' : Invalid value specified for parameter lang
The last example can also benefit from the other string literal notation which allows us to avoid having to type all the backslash escaping characters.
Since a Matcher coerces to a boolean by calling its find method, the =~ operator is consistent with the simple use of Perl's =~ operator, when it appears as a predicate (in 'if', 'while', etc.). The "stricter-looking" ==~ operator requires an exact match of the whole subject string.
Labels