Java String.matches(String regex)

Syntax

String.matches(String regex) has the following syntax.

public boolean matches(String regex)

Example

In the following code shows how to use String.matches(String regex) method.


//from   www.j  a v  a2 s. com
public class Main {

  public static void main(String[] args) {
  
    String str1 = "java2s", str2 = "java2s.com";
    
    boolean retval = str1.matches(str2);

    System.out.println("Value returned = " + retval);

    retval = str2.matches("com");

    System.out.println("Value returned = " + retval);    

    retval = str1.matches("java");

    System.out.println("Value returned = " + retval);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable