Groovy – replaceAll()

  • Post author:
  • Post category:Groovy
  • Post comments:0 Comments
Replaces all

Replaces all occurrences of a captured group by the result of closure on that text.

Syntax

void replaceAll(String regex, String replacement)

Parameters

  • regex − the regular expression to which this string is to be matched.
  • replacement − the string which would replace found expression.

Return Value

This method returns the resulting String.

Example

Following is an example of the usage of this method −

class Example { 
   static void main(String[] args) { 
      String a = "Hello World Hello"; 
      println(a.replaceAll("Hello","Bye")); 
      println(a.replaceAll("World","Hello"));     
   } 
}

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

Bye World Bye 
Hello Hello Hello

Previous Page:-Click Here

Leave a Reply