WEB DEVELOPER SITE
PHP7
 

Java String matches() Method



Tells whether or not this string matches the given regular expression.


Syntax

Here is the syntax of this method โˆ’

public boolean matches(String regex)

Parameters

Here is the detail of parameters โˆ’

  • regex โˆ’ the regular expression to which this string is to be matched.

Return Value

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

Example

There are following example
import java.io.*;
public class Test {

   public static void main(String args[]) {
      String Str = new String("Welcome to welookups.com");

      System.out.print("Return Value :" );
      System.out.println(Str.matches("(.*)w(.*)"));

      System.out.print("Return Value :" );
      System.out.println(Str.matches("we"));

      System.out.print("Return Value :" );
      System.out.println(Str.matches("Welcome(.*)"));
   }
}

 

Run example ยป