Home Regularexpressions Pointing last index of the Matcher



Pointing last index of the Matcher
Posted on: August 29, 2008 at 12:00 AM
This Example describes the way to point the matcher and also indicate the last index of the matcher using expression.

Pointing last index of the Matcher

     

This Example describes the way to point the matcher and also indicate the last index of the matcher using expression.For this we are going to make program named Matcher_end.java. The steps involved in program Matcher_end.java are described below:-

String text = "My name is Tim.In October Tim will arrive.":- Declaring text as String in which last index of word Tim is to be pointed out.

Pattern p=Pattern.compile("Tim"):- Creating a pattern object and compiles the given regular expression into a pattern.

Matcher m=p.matcher(text):- Creates a matcher for matching the given input against pattern p.

 

 

 

programname.java

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Matcher_end {

  public static void main(String[] args) {
 String text = "My name is Tim.In October Tim will arrive.";
   
  Pattern p=Pattern.compile("Tim");
String matcher[]={"  ^","   ^"};
 
  Matcher m=p.matcher(text);
  m.find();
  int index=m.end();
  System.out.println(text);
  System.out.println(matcher[0]+index);
  
  m.find();
  int index1=m.end();
  System.out.println(text);
  System.out.println(matcher[1]+index1);
  }
}

Output of the program:-

My name is Tim.In October Tim will arrive.
    ^14
My name is Tim.In October Tim will arrive.
     ^29

DownLoad Source Code

Related Tags for Pointing last index of the Matcher:
javaciomakeexpressionnameusingintthisforpoiindexexampleprogrammatchtopointexpressramexamastssielastdeslsinasmntcajesendnamedmeprocatdescribexaxampssoessatkmatcherismplpresspregoandarxpvascrssrithavbesstlsoindicicaicapleplprndonogro


More Tutorials from this section

Ask Questions?    Discuss: Pointing last index of the Matcher  

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.