==~ patternQuoted\nprintln \"It's a Boolean for Quoted Pattern!: ${findRegExCookbook31ExactMatchQuoted2.class}\"\nprintln \"t${findRegExCookbook31ExactMatchQuoted2 ? 'Exact Match!' : 'NOT Exact Match.'}\"\n\ndef findRegExCookbook31ExactMatchSlashy2 = ' ==~ patternSlashy\nprintln \"It's a Boolean for Quoted Pattern!: ${findRegExCookbook31ExactMatchSlashy2.class}\"\nprintln \"t${findRegExCookbook31ExactMatchSlashy2 ? 'Exact Match!' : 'NOT Exact Match.'}\"\nThe output from running this, shown in the next screen snapshot, tells the tale.This output confirms that the Groovy =~ operator provides a Matcher instance that is smarter than your average Matcher. That's because the Groovy Matcher (part of Groovy GDK) provides many additional utility methods including two used in the code above (getCount() used as count property and size() method). The GDK's Matcher.asBoolean() method is behind the magic that allows a Groovy Matcher to return a boolean in a conditional expression. I don't discuss it here, but the GDK does provide one small extension to the Pattern class as well.Mr. Haki provides a nice overview of Groovy's treatment of regular expressions via Matchers in his post Groovy Goodness: Matchers for Regular Expressions. He similarly covers Groovy handling of Patterns in the post Groovy Goodness: Using Regular Expression Pattern Class.ConclusionThe ability to use more natural-looking (at least by regular expressions standards) regular expressions, the ability to use operators rather than APIs and method calls, and the extra \"smarts\" added to GDK's extensions of the Java RegEx library make using regular expressions in Groovy easier and more natural to the people who are probably most familiar with regular expressions: script writers. As is true with most of Groovy, Groovy's regular expression support is a reflection of Java's regular expression support. Generally speaking, anything one knows about regular expressions in Java (including the syntax supported in Java's flavor\/dialect) can be applied when using regular expressions in Groovy. In several cases, though, Grooy makes it easier to use. With anything, but especially with regular expressions, easier is always better.Additional ResourcesI mentioned previously that there are numerous great online resources on Groovy's support for regular expressions. Some of them are listed here. I especially recommend the first listed resource (Groovy: Don't Fear the RegExp) and book I frequently cited in this post (Regular Expressions Cookbook).\u21d2 Regular Expressions Cookbook\u21d2 Groovy: Don\u2019t Fear the RegExp\u21d2 Groovy Regular Expressions\u21d2 Groovy Tutorial 4 - Groovy Regular Expressions Basics\u21d2 Groovy Goodness: Using Regular Expression Pattern Class\u21d2 Groovy Goodness: Matchers for Regular Expressions\u21d2 Big Collection of Regular Expressions (not specific to Groovy)\u21d2 Finding Files by Name with Groovy\u21d2 Online Regular Expression Test Page (uses java.util.regex)\u21d2 RegexBuddy\u21d2 RegexPal\u21d2 Regular Expression ToolOriginal Post Available at https:\/\/marxsoftware.blogspot.com\/.","wordCount":3408,"datePublished":"2010-12-29T20:47:00-05:00","dateModified":"2010-12-29T20:47:00-05:00","keywords":"Software Development,Groovy,NetBeans","mainEntityOfPage":"https:\/\/www.infoworld.com\/article\/2160864\/regular-expressions-in-groovy-via-java.html"}]