Friday, May 29, 2009

Matcher class

Matcher is a final class present in the java.util.regex package. It is used to match a regular expression using the pattern defined by the Pattern class.

The Matcher class defines no public constructors. It is created from a pattern by invoking the Pattern's matcher method as follows:

public Matcher matcher(CharSequence input)

This method creates a matcher that will match the given input against the given pattern.

The other important methods of the Matcher class are as follows:

  • int start(): This method returns the index of the first character matched.

  • public int end(): This method returns the index of the last character matched, plus one.

  • boolean find(): This method searches the subsequence of the input sequence that matches the pattern. It returns true if the match is found; otherwise, it returns false.

  • boolean lookingAt(): This method searches through the input sequence to match the pattern. It returns true if the match is found; otherwise, it returns false.

No comments:

Post a Comment