java.util.regex

Class Matcher


public final class Matcher
extends Object

Instance of a regular expression applied to a char sequence.

Since:
1.4

Method Summary

Matcher
appendReplacement(StringBuffer sb, String replacement)
StringBuffer
appendTail(StringBuffer sb)
int
end()
int
end(int group)
boolean
find()
boolean
find(int start)
String
group()
String
group(int group)
int
groupCount()
boolean
lookingAt()
boolean
matches()
Attempts to match the entire input sequence against the pattern.
Pattern
pattern()
Returns the Pattern that is interpreted by this Matcher
String
replaceAll(String replacement)
String
replaceFirst(String replacement)
Matcher
reset()
Matcher
reset(CharSequence input)
int
start()
int
start(int group)

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Details

appendReplacement

public Matcher appendReplacement(StringBuffer sb,
                                 String replacement)
            throws IllegalStateException

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

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


end

public int end(int group)
            throws IllegalStateException

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)
            throws IllegalStateException

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()


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

Parameters:

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


start

public int start(int group)
            throws IllegalStateException

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


Matcher.java -- Instance of a regular expression applied to a char sequence. Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.