Groovy – matches()

  • Post author:
  • Post category:Groovy
  • Post comments:1 Comment
Matches

It outputs whether a String matches the given regular expression.

Syntax

Boolean matches(String regex)

Parameters

Regex − the expression for comparison.

Return Value

This method returns true if, and only if, this string matches the given regular expression.

Following is an example of the usage of this method-

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

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

false 
true

Previous Page:-Click Here

This Post Has One Comment

Leave a Reply