Friday, April 10, 2009

New find and findAll methods for String in Groovy 1.6.1

In Ted Naleid's blog, he describes the patches to the String class that he contributed to the Groovy community recently. The patches have been released as Groovy 1.6.1 on April 7, 2009.

He listed the following new methods:

  • eachMatch(Pattern pattern) { fullMatch, group1, ... -> ... }

  • find(String regex)

  • find(String regex) { fullMatch, group1, ... -> ... }

  • find(Pattern pattern)

  • find(Pattern pattern) { fullMatch, group1, ... -> ... }

  • findAll(String regex)

  • findAll(String regex) { fullMatch, group1, ... -> ... }

  • findAll(Pattern pattern)

  • findAll(Pattern pattern) { fullMatch, group1, ... -> ... }


In other words, the find/findAll methods now accepts a regular expression and the matching groups are passed to the closure.

Thanks for the patches, Ted.

1 comment:

Ted Naleid said...

You're welcome, I hope others will get as much use out of it as I will :).