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