java.util.regex

Class Matcher

public final class Matcher extends Object implements MatchResult

Instance of a regular expression applied to a char sequence.

Since: 1.4

Method Summary
MatcherappendReplacement(StringBuffer sb, String replacement)
StringBufferappendTail(StringBuffer sb)
intend()
intend(int group)
booleanfind()
booleanfind(int start)
Stringgroup()
Stringgroup(int group)
intgroupCount()
booleanhitEnd()
booleanlookingAt()
booleanmatches()
Attempts to match the entire input sequence against the pattern.
Patternpattern()
Returns the Pattern that is interpreted by this Matcher
StringreplaceAll(String replacement)
StringreplaceFirst(String replacement)
Matcherreset()
Matcherreset(CharSequence input)
intstart()
intstart(int group)
StringtoString()

Method Detail

appendReplacement

public Matcher appendReplacement(StringBuffer sb, String replacement)

Parameters: sb The target string buffer replacement The replacement string

Throws: IllegalStateException If no match has yet been attempted, or if the previous match operation failed IndexOutOfBoundsException If the replacement string refers to a capturing group that does not exist in the pattern

appendTail

public StringBuffer appendTail(StringBuffer sb)

Parameters: sb The target string buffer

end

public int end()

Throws: IllegalStateException If no match has yet been attempted, or if the previous match operation failed

end

public int end(int group)

Parameters: group The index of a capturing group in this matcher's pattern

Throws: IllegalStateException If no match has yet been attempted, or if the previous match operation failed IndexOutOfBoundsException If the replacement string refers to a capturing group that does not exist in the pattern

find

public boolean find()

find

public boolean find(int start)

Parameters: start The index to start the new pattern matching

Throws: IndexOutOfBoundsException If the replacement string refers to a capturing group that does not exist in the pattern

group

public String group()

Throws: IllegalStateException If no match has yet been attempted, or if the previous match operation failed

group

public String group(int group)

Parameters: group The index of a capturing group in this matcher's pattern

Throws: IllegalStateException If no match has yet been attempted, or if the previous match operation failed IndexOutOfBoundsException If the replacement string refers to a capturing group that does not exist in the pattern

groupCount

public int groupCount()

hitEnd

public boolean hitEnd()

Returns: True if and only if the matcher hit the end of input.

lookingAt

public boolean lookingAt()

matches

public boolean matches()
Attempts to match the entire input sequence against the pattern. If the match succeeds then more information can be obtained via the start, end, and group methods.

See Also: start end group

pattern

public Pattern pattern()
Returns the Pattern that is interpreted by this Matcher

replaceAll

public String replaceAll(String replacement)

Parameters: replacement The replacement string

replaceFirst

public String replaceFirst(String replacement)

Parameters: replacement The replacement string

reset

public Matcher reset()

reset

public Matcher reset(CharSequence input)

Parameters: input The new input character sequence

start

public int start()

Throws: IllegalStateException If no match has yet been attempted, or if the previous match operation failed

UNKNOWN: the index of a capturing group in this matcher's pattern

start

public int start(int group)

Parameters: group The index of a capturing group in this matcher's pattern

Throws: IllegalStateException If no match has yet been attempted, or if the previous match operation failed IndexOutOfBoundsException If the replacement string refers to a capturing group that does not exist in the pattern

toString

public String toString()

Returns: A string expression of this matcher.