Matching Pattern using Regularexpression

This Example describe the way to match a pattern with the text by using Regularexpression.

Ads

Matching Pattern using Regularexpression

     

This Example describe the way to match a pattern with the text by using Regularexpression.The steps involved in matching a pattern  with the text are described below:

 String ptrn="1\\+1=2":-it is the pattern to define expression (1+1=2) using regularexpression.

 String text="1+1=2":-it is the text which is to be matched with the pattern defined above.

 

 

 

StringConvenience.java

import java.util.regex.*;
public class StringConvenience {

  public static void main(String[] args) {
 String ptrn="1\\+1=2";
 
  String text="1+1=2";
  if(text.matches(ptrn)){
  System.out.println(text+"\t"+ptrn);
  }else{
  System.out.println("no match");
  }
  }
}

output of the program:-

1+1=2 matches  1\+1=2

Download Source code

Advertisements

Ads
Share on Google+Share on Google+

Matching Pattern using Regularexpression

Posted on: August 26, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Matching Pattern using Regularexpression  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads