Mega Code Archive

 
Categories / Java Book / 003 Essential Classes
 

0217 Matcher

Once you have created a Matcher, you will use its methods to do various pattern matching operations. Matcher defines the following methods: boolean matches( ) determines whether the character sequence matches the pattern. It returns true if the sequence and the pattern match, and false otherwise. boolean find( ) To determine if a subsequence of the input sequence matches the pattern. It returns true if there is a matching subsequence and false otherwise. This method can be called repeatedly to find all matching subsequences. String group( ) returns a string containing the last matching sequence by calling group( ). int start( ) returns the index within the input sequence of the current match int end( ) return the index past the end of the current match. String replaceAll(String newStr) replace all occurrences of a matching sequence with another sequence. The updated input sequence is returned as a string. In general, a regular expression is comprised of normal characters, character classes, wildcard characters, and quantifiers.