Groovy – eachMatch()

  • Post author:
  • Post category:Groovy
  • Post comments:0 Comments
each

Processes each regex group (see next section) matched substring of the given String.

Syntax

void eachMatch(String regex, Closure clos)

Parameters

  • Regex – The string expression to search for
  • Closure – optional closure

Return Value

No return value.

Example

Following is an example of the usage of this method −

class Example {
   static void main(String[] args) {
      String s = "HelloWorld";
      
      s.eachMatch(".") {
         ch -> println ch
      }
   }
}

When we run the above program, we will get the following result −

H 
e 
l 
l 
o 
W 
o 
r 
l 
d

Previous Page:-Click Here

Leave a Reply