Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Matcher class and Matcher object of Regular Expression

    • 0
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 213
    Comment on it

    Matcher object can be created after invoking the matcher methods which interprets the given pattern and perform the match operation. Matcher class implements MatchResult interface. Matcher class do not have public constructor.

    Below are the methods by which match operation will be performed.

     

    1. Index Methods

    Below these index methods provide index values if the match was found in given input string.

    1> public int start(): This method returns the start index of the input string which aims to match with regex pattern.

    2> public int start(int group): This method returns the start index of the subsequence captured group which aims to match with regex pattern.

    3> public int end(): This method returns the index of last matched character.

    4> public int end(int group): This method returns the index of last character of subsequent captured group.

     

    2. Study Methods

    Below these study methods provide the boolean value if the match was found in given input string.

    1> public boolean lookingAt(): Match input string from starting with the provided regex pattern and return the boolean value after match operation perform.

    2> public boolean find(): This method reads the next subsequent character of provided input and matches with pattern.

    3> public boolean find(int start): This matcher find the next subsequent character of given input with provided start index that matches with pattern.

    4> public boolean matches(): This matcher matches the whole pattern with regex and returns boolean value of true or false.

     

    3. Replacement Methods

    Replacement methods are useful methods for replacing text in an input string.

    1> public Matcher appendReplacement(StringBuffer sb, String replacement): This method implement a non-terminal character which store in a string buffer and append-and-replace with provided character.

    2> public StringBuffer appendTail(StringBuffer sb): This method implements the last character of the string and append it and then replace it with provided character.

    3> public String replaceAll(String replacement): After invoking, this method replace every subsequence of the input string that matches the pattern.

    4> public String replaceFirst(String replacement): After invoking, this method replaces the first character of the input string and matches the pattern.

    5> public static String quoteReplacement(String s): After invoking, this method returns a literal replacement String for given input string. The result of this method a string that will work as a literal replacement in the appendReplacement method of the matcher class.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: