Home Regularexpressions Matching Pattern using Regularexpression



Matching Pattern using Regularexpression
Posted on: August 26, 2008 at 12:00 AM
This Example describe the way to match a pattern with the text by using Regularexpression.

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  nt>{

  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

Related Tags for Matching Pattern using Regularexpression:
ctextioexpressionpatternusingthistexexamplewithmatchtoexpressexamssiexteitdesulinmesdescribexaxampsessatismplpressprearxpxtttscrssrithpleplprono


More Tutorials from this section

Ask Questions?    Discuss: Matching Pattern using Regularexpression  

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.