News:

MyKidsDiary.in :: Capture your kids magical moment and create your Online Private Diary for your kids

Main Menu

Java String matches Example

Started by VelMurugan, Nov 26, 2008, 07:43 PM

Previous topic - Next topic

VelMurugan

Java String matches Example

String class matches method example

String class matches method example. This example shows you how to use matches method.This method Tells whether or not this string matches the given regular expression.
Syntax:-matches(String regex)

Here is the code:-

/*
* @(#) Matchesstring.java
*Program Shows Tells whether or not this string matches the given regular expression.
* @Version  01-May-2008
* @author   Rose India Team
*/

//import java.util.regex.Pattern;
import java.util.regex.*;
public class Matchesstring
  {
  public static void main(String args[])
    {
    String regex = "ad*";
    String input = "add";
    boolean isMatch = Pattern.matches(regex,input);
    System.out.println(isMatch);//return true
  }
}


Source : CodeDiary