Groovy Regexes

I added native regular expression support in the form of an operator. Check it out and see if you like it.

In the current build of groovy you can now use regular expressions to compare strings with this simple syntax:

“string to compare” ~= “g.*t”

This will return a java.util.regex.Matcher that you can either check as a boolean which will .find() the regex in the string or you can manipulate it directly as a Matcher object. Additionally you can also use a more restrictive form:

“string” ~== “^s.*g$”

This returns a boolean only, true if the regex matches the entire string or false if it does not. You can find examples in the groovy unit test for regexes, RegularExpressionsTest.

This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

blog comments powered by Disqus