# Matcher

public final class **Matcher** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
implements [MatchResult](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/MatchResult.html) J2ObjC modified: Synchronizations are removed because they were added in the Android sources
to safeguard against hard-to-debug crashes from incorrect concurrent use of this class.

### Public Method Summary

|---|---|
| [Matcher](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html) | [appendReplacement](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#appendReplacement(java.lang.StringBuilder,%20java.lang.String))([StringBuilder](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/StringBuilder.html) buffer, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) replacement) Appends a literal part of the input plus a replacement for the current match to a given `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/StringBuilder.html`. |
| [Matcher](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html) | [appendReplacement](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#appendReplacement(java.lang.StringBuffer,%20java.lang.String))([StringBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/StringBuffer.html) sb, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) replacement) Implements a non-terminal append-and-replace step. |
| [StringBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/StringBuffer.html) | [appendTail](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#appendTail(java.lang.StringBuffer))([StringBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/StringBuffer.html) sb) Implements a terminal append-and-replace step. |
| [StringBuilder](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/StringBuilder.html) | [appendTail](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#appendTail(java.lang.StringBuilder))([StringBuilder](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/StringBuilder.html) buffer) Appends the (unmatched) remainder of the input to the given `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/StringBuilder.html`. |
| int | [end](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#end(int))(int group) Returns the offset after the last character of the subsequence captured by the given group during the previous match operation. |
| int | [end](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#end(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) name) Returns the offset after the last character of the subsequence captured by the given [named-capturing group](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Pattern#groupname) during the previous match operation. |
| int | [end](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#end())() Returns the offset after the last character matched. |
| boolean | [find](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#find())() Attempts to find the next subsequence of the input sequence that matches the pattern. |
| boolean | [find](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#find(int))(int start) Resets this matcher and then attempts to find the next subsequence of the input sequence that matches the pattern, starting at the specified index. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [group](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#group(int))(int group) Returns the input subsequence captured by the given group during the previous match operation. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [group](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#group(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) name) Returns the input subsequence captured by the given [named-capturing group](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Pattern#groupname) during the previous match operation. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [group](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#group())() Returns the input subsequence matched by the previous match. |
| int | [groupCount](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#groupCount())() Returns the number of capturing groups in this matcher's pattern. |
| boolean | [hasAnchoringBounds](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#hasAnchoringBounds())() Queries the anchoring of region bounds for this matcher. |
| boolean | [hasTransparentBounds](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#hasTransparentBounds())() Queries the transparency of region bounds for this matcher. |
| boolean | [hitEnd](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#hitEnd())() Returns true if the end of input was hit by the search engine in the last match operation performed by this matcher. |
| boolean | [lookingAt](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#lookingAt())() Attempts to match the input sequence, starting at the beginning of the region, against the pattern. |
| boolean | [matches](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#matches())() Attempts to match the entire region against the pattern. |
| [Pattern](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Pattern.html) | [pattern](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#pattern())() Returns the pattern that is interpreted by this matcher. |
| static [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [quoteReplacement](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#quoteReplacement(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) s) Returns a literal replacement `String` for the specified `String`. |
| [Matcher](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html) | [region](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#region(int,%20int))(int start, int end) Sets the limits of this matcher's region. |
| int | [regionEnd](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#regionEnd())() Reports the end index (exclusive) of this matcher's region. |
| int | [regionStart](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#regionStart())() Reports the start index of this matcher's region. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [replaceAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#replaceAll(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) replacement) Replaces every subsequence of the input sequence that matches the pattern with the given replacement string. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [replaceFirst](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#replaceFirst(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) replacement) Replaces the first subsequence of the input sequence that matches the pattern with the given replacement string. |
| boolean | [requireEnd](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#requireEnd())() Returns true if more input could change a positive match into a negative one. |
| [Matcher](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html) | [reset](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#reset(java.lang.CharSequence))([CharSequence](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/CharSequence.html) input) Resets this matcher with a new input sequence. |
| [Matcher](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html) | [reset](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#reset())() Resets this matcher. |
| int | [start](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#start())() Returns the start index of the previous match. |
| int | [start](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#start(int))(int group) Returns the start index of the subsequence captured by the given group during the previous match operation. |
| int | [start](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#start(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) name) Returns the start index of the subsequence captured by the given [named-capturing group](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Pattern#groupname) during the previous match operation. |
| [MatchResult](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/MatchResult.html) | [toMatchResult](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#toMatchResult())() Returns the match state of this matcher as a `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/MatchResult.html`. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#toString())() Returns the string representation of this matcher. |
| [Matcher](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html) | [useAnchoringBounds](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#useAnchoringBounds(boolean))(boolean b) Sets the anchoring of region bounds for this matcher. |
| [Matcher](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html) | [usePattern](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#usePattern(java.util.regex.Pattern))([Pattern](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Pattern.html) newPattern) Changes the Pattern that this Matcher uses to find matches with. |
| [Matcher](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html) | [useTransparentBounds](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#useTransparentBounds(boolean))(boolean b) Sets the transparency of region bounds for this matcher. |

### Protected Method Summary

|---|---|
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

From interface [java.util.regex.MatchResult](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/MatchResult.html)

|---|---|
| abstract int | [end](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/MatchResult.html#end(int))(int group) Returns the offset after the last character of the subsequence captured by the given group during this match. |
| abstract int | [end](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/MatchResult.html#end())() Returns the offset after the last character matched. |
| abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [group](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/MatchResult.html#group(int))(int group) Returns the input subsequence captured by the given group during the previous match operation. |
| abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [group](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/MatchResult.html#group())() Returns the input subsequence matched by the previous match. |
| abstract int | [groupCount](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/MatchResult.html#groupCount())() Returns the number of capturing groups in this match result's pattern. |
| abstract int | [start](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/MatchResult.html#start())() Returns the start index of the match. |
| abstract int | [start](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/MatchResult.html#start(int))(int group) Returns the start index of the subsequence captured by the given group during this match. |

## Public Methods

#### public [Matcher](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html)
**appendReplacement**
([StringBuilder](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/StringBuilder.html) buffer, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) replacement)

Appends a literal part of the input plus a replacement for the current
match to a given `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/StringBuilder.html`. The literal part is exactly the
part of the input between the previous match and the current match. The
method can be used in conjunction with `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#find()` and
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#appendTail(java.lang.StringBuilder)` to walk through the input and replace
all occurrences of the `Pattern` with something else.

##### Parameters

| buffer | the `StringBuilder` to append to. |
| replacement | the replacement text. |
|---|---|

##### Returns

- the `Matcher` itself.

##### Throws

| [IllegalStateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | if no successful match has been made. |
|---|---|

#### public [Matcher](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html)
**appendReplacement**
([StringBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/StringBuffer.html) sb, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) replacement)

Implements a non-terminal append-and-replace step.

This method performs the following actions:

1. It reads characters from the input sequence, starting at the
   append position, and appends them to the given string buffer. It
   stops after reading the last character preceding the previous match,
   that is, the character at index `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#start()` - 1.

2. It appends the given replacement string to the string buffer.

3. It sets the append position of this matcher to the index of
   the last character matched, plus one, that is, to `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#end()`.

The replacement string may contain references to subsequences
captured during the previous match: Each occurrence of
${*name*} or $*g*
will be replaced by the result of evaluating the corresponding
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#group(java.lang.String)` or `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#group(int)`
respectively. For $*g*,
the first number after the $ is always treated as part of
the group reference. Subsequent numbers are incorporated into g if
they would form a legal group reference. Only the numerals '0'
through '9' are considered as potential components of the group
reference. If the second group matched the string "foo", for
example, then passing the replacement string "$2bar" would
cause "foobar" to be appended to the string buffer. A dollar
sign ($) may be included as a literal in the replacement
string by preceding it with a backslash (\\$).

Note that backslashes (\\) and dollar signs ($) in
the replacement string may cause the results to be different than if it
were being treated as a literal replacement string. Dollar signs may be
treated as references to captured subsequences as described above, and
backslashes are used to escape literal characters in the replacement
string.

This method is intended to be used in a loop together with the
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#appendTail(java.lang.StringBuffer)` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#find()` methods. The
following code, for example, writes one dog two dogs in the yard to the standard-output stream:
>
> ```
>  Pattern p = Pattern.compile("cat");
>  Matcher m = p.matcher("one cat two cats in the yard");
>  StringBuffer sb = new StringBuffer();
>  while (m.find()) {
>      m.appendReplacement(sb, "dog");
>  }
>  m.appendTail(sb);
>  System.out.println(sb.toString());
> ```

<br />

##### Parameters

| sb | The target string buffer |
| replacement | The replacement string |
|---|---|

##### Returns

- This matcher

##### Throws

| [IllegalStateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | If no match has yet been attempted, or if the previous match operation failed |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | If the replacement string refers to a named-capturing group that does not exist in the pattern |
| [IndexOutOfBoundsException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IndexOutOfBoundsException.html) | If the replacement string refers to a capturing group that does not exist in the pattern |
|---|---|

#### public [StringBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/StringBuffer.html)
**appendTail**
([StringBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/StringBuffer.html) sb)

Implements a terminal append-and-replace step.

This method reads characters from the input sequence, starting at
the append position, and appends them to the given string buffer. It is
intended to be invoked after one or more invocations of the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#appendReplacement(java.lang.StringBuffer,%20java.lang.String)` method in order to copy the
remainder of the input sequence.

<br />

##### Parameters

| sb | The target string buffer |
|---|---|

##### Returns

- The target string buffer

#### public [StringBuilder](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/StringBuilder.html)
**appendTail**
([StringBuilder](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/StringBuilder.html) buffer)

Appends the (unmatched) remainder of the input to the given
`https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/StringBuilder.html`. The method can be used in conjunction with
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#find()` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#appendReplacement(java.lang.StringBuilder,%20java.lang.String)` to
walk through the input and replace all matches of the `Pattern`
with something else.

##### Parameters

| buffer |   |
|---|---|

##### Returns

- the `StringBuilder`.

##### Throws

| [IllegalStateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | if no successful match has been made. |
|---|---|

#### public int
**end**
(int group)

Returns the offset after the last character of the subsequence
captured by the given group during the previous match operation.

[Capturing groups](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Pattern#cg) are indexed from left
to right, starting at one. Group zero denotes the entire pattern, so
the expression *m.*end(0) is equivalent to
*m.*end().

<br />

##### Parameters

| group | The index of a capturing group in this matcher's pattern |
|---|---|

##### Returns

- The offset after the last character captured by the group, or -1 if the match was successful but the group itself did not match anything

##### Throws

| [IllegalStateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | If no match has yet been attempted, or if the previous match operation failed |
| [IndexOutOfBoundsException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IndexOutOfBoundsException.html) | If there is no capturing group in the pattern with the given index |
|---|---|

#### public int
**end**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) name)

Returns the offset after the last character of the subsequence
captured by the given [named-capturing
group](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Pattern#groupname) during the previous match operation.

##### Parameters

| name | The name of a named-capturing group in this matcher's pattern |
|---|---|

##### Returns

- The offset after the last character captured by the group, or `-1` if the match was successful but the group itself did not match anything

##### Throws

| [IllegalStateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | If no match has yet been attempted, or if the previous match operation failed |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | If there is no capturing group in the pattern with the given name |
|---|---|

#### public int
**end**
()

Returns the offset after the last character matched.

##### Returns

- The offset after the last character matched

##### Throws

| [IllegalStateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | If no match has yet been attempted, or if the previous match operation failed |
|---|---|

#### public boolean
**find**
()

Attempts to find the next subsequence of the input sequence that matches
the pattern.

This method starts at the beginning of this matcher's region, or, if
a previous invocation of the method was successful and the matcher has
not since been reset, at the first character not matched by the previous
match.

If the match succeeds then more information can be obtained via the
start, end, and group methods.

<br />

##### Returns

- true if, and only if, a subsequence of the input sequence matches this matcher's pattern

#### public boolean
**find**
(int start)

Resets this matcher and then attempts to find the next subsequence of
the input sequence that matches the pattern, starting at the specified
index.

If the match succeeds then more information can be obtained via the
start, end, and group methods, and subsequent
invocations of the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#find()` method will start at the first
character not matched by this match.

<br />

##### Parameters

| start | the index to start searching for a match |
|---|---|

##### Returns

- true if, and only if, a subsequence of the input sequence starting at the given index matches this matcher's pattern

##### Throws

| [IndexOutOfBoundsException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IndexOutOfBoundsException.html) | If start is less than zero or if start is greater than the length of the input sequence. |
|---|---|

#### public [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**group**
(int group)

Returns the input subsequence captured by the given group during the
previous match operation.

For a matcher *m*, input sequence *s*, and group index
*g*, the expressions *m.*group(*g*) and
*s.*substring(*m.*start(*g*), *m.*end(*g*))
are equivalent.

[Capturing groups](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Pattern#cg) are indexed from left
to right, starting at one. Group zero denotes the entire pattern, so
the expression m.group(0) is equivalent to m.group().

If the match was successful but the group specified failed to match
any part of the input sequence, then null is returned. Note
that some groups, for example (a\*), match the empty string.
This method will return the empty string when such a group successfully
matches the empty string in the input.

<br />

##### Parameters

| group | The index of a capturing group in this matcher's pattern |
|---|---|

##### Returns

- The (possibly empty) subsequence captured by the group during the previous match, or null if the group failed to match part of the input

##### Throws

| [IllegalStateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | If no match has yet been attempted, or if the previous match operation failed |
| [IndexOutOfBoundsException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IndexOutOfBoundsException.html) | If there is no capturing group in the pattern with the given index |
|---|---|

#### public [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**group**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) name)

Returns the input subsequence captured by the given
[named-capturing group](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Pattern#groupname) during the previous
match operation.

If the match was successful but the group specified failed to match
any part of the input sequence, then null is returned. Note
that some groups, for example (a\*), match the empty string.
This method will return the empty string when such a group successfully
matches the empty string in the input.

<br />

##### Parameters

| name | The name of a named-capturing group in this matcher's pattern |
|---|---|

##### Returns

- The (possibly empty) subsequence captured by the named group during the previous match, or null if the group failed to match part of the input

##### Throws

| [IllegalStateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | If no match has yet been attempted, or if the previous match operation failed |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | If there is no capturing group in the pattern with the given name |
|---|---|

#### public [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**group**
()

Returns the input subsequence matched by the previous match.

For a matcher *m* with input sequence *s*,
the expressions *m.*group() and
*s.*substring(*m.*start(), *m.*end())
are equivalent.

Note that some patterns, for example a\*, match the empty
string. This method will return the empty string when the pattern
successfully matches the empty string in the input.

<br />

##### Returns

- The (possibly empty) subsequence matched by the previous match, in string form

##### Throws

| [IllegalStateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | If no match has yet been attempted, or if the previous match operation failed |
|---|---|

#### public int
**groupCount**
()

Returns the number of capturing groups in this matcher's pattern.

Group zero denotes the entire pattern by convention. It is not
included in this count.

Any non-negative integer smaller than or equal to the value
returned by this method is guaranteed to be a valid group index for
this matcher.

<br />

##### Returns

- The number of capturing groups in this matcher's pattern

#### public boolean
**hasAnchoringBounds**
()

Queries the anchoring of region bounds for this matcher.

This method returns true if this matcher uses
*anchoring* bounds, false otherwise.

See `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#useAnchoringBounds(boolean)` for a
description of anchoring bounds.

By default, a matcher uses anchoring region boundaries.

##### Returns

- true iff this matcher is using anchoring bounds, false otherwise.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#useAnchoringBounds(boolean)`

#### public boolean
**hasTransparentBounds**
()

Queries the transparency of region bounds for this matcher.

This method returns true if this matcher uses
*transparent* bounds, false if it uses *opaque*
bounds.

See `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#useTransparentBounds(boolean)` for a
description of transparent and opaque bounds.

By default, a matcher uses opaque region boundaries.

##### Returns

- true iff this matcher is using transparent bounds, false otherwise.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#useTransparentBounds(boolean)`

#### public boolean
**hitEnd**
()

<br />

Returns true if the end of input was hit by the search engine in
the last match operation performed by this matcher.

When this method returns true, then it is possible that more input
would have changed the result of the last search.

##### Returns

- true iff the end of input was hit in the last match; false otherwise

#### public boolean
**lookingAt**
()

Attempts to match the input sequence, starting at the beginning of the
region, against the pattern.

Like the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#matches()` method, this method always starts
at the beginning of the region; unlike that method, it does not
require that the entire region be matched.

If the match succeeds then more information can be obtained via the
start, end, and group methods.

<br />

##### Returns

- true if, and only if, a prefix of the input sequence matches this matcher's pattern

#### public boolean
**matches**
()

Attempts to match the entire region against the pattern.

If the match succeeds then more information can be obtained via the
start, end, and group methods.

<br />

##### Returns

- true if, and only if, the entire region sequence matches this matcher's pattern

#### public [Pattern](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Pattern.html)
**pattern**
()

Returns the pattern that is interpreted by this matcher.

##### Returns

- The pattern for which this matcher was created

#### public static [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**quoteReplacement**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) s)

Returns a literal replacement `String` for the specified
`String`.

This method produces a `String` that will work
as a literal replacement `s` in the
`appendReplacement` method of the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html` class.
The `String` produced will match the sequence of characters
in `s` treated as a literal sequence. Slashes ('\\') and
dollar signs ('$') will be given no special meaning.

##### Parameters

| s | The string to be literalized |
|---|---|

##### Returns

- A literal string replacement

#### public [Matcher](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html)
**region**
(int start, int end)

Sets the limits of this matcher's region. The region is the part of the
input sequence that will be searched to find a match. Invoking this
method resets the matcher, and then sets the region to start at the
index specified by the `start` parameter and end at the
index specified by the `end` parameter.

Depending on the transparency and anchoring being used (see
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#useTransparentBounds(boolean)` and
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#useAnchoringBounds(boolean)`), certain constructs such
as anchors may behave differently at or around the boundaries of the
region.

##### Parameters

| start | The index to start searching at (inclusive) |
| end | The index to end searching at (exclusive) |
|---|---|

##### Returns

- this matcher

##### Throws

| [IndexOutOfBoundsException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IndexOutOfBoundsException.html) | If start or end is less than zero, if start is greater than the length of the input sequence, if end is greater than the length of the input sequence, or if start is greater than end. |
|---|---|

#### public int
**regionEnd**
()

Reports the end index (exclusive) of this matcher's region.
The searches this matcher conducts are limited to finding matches
within `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#regionStart()` (inclusive) and
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#regionEnd()` (exclusive).

##### Returns

- the ending point of this matcher's region

#### public int
**regionStart**
()

Reports the start index of this matcher's region. The
searches this matcher conducts are limited to finding matches
within `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#regionStart()` (inclusive) and
`https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#regionEnd()` (exclusive).

##### Returns

- The starting point of this matcher's region

#### public [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**replaceAll**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) replacement)

Replaces every subsequence of the input sequence that matches the
pattern with the given replacement string.

This method first resets this matcher. It then scans the input
sequence looking for matches of the pattern. Characters that are not
part of any match are appended directly to the result string; each match
is replaced in the result by the replacement string. The replacement
string may contain references to captured subsequences as in the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#appendReplacement(java.lang.StringBuffer,%20java.lang.String)` method.

Note that backslashes (\\) and dollar signs ($) in
the replacement string may cause the results to be different than if it
were being treated as a literal replacement string. Dollar signs may be
treated as references to captured subsequences as described above, and
backslashes are used to escape literal characters in the replacement
string.

Given the regular expression a\*b, the input
"aabfooaabfooabfoob", and the replacement string
"-", an invocation of this method on a matcher for that
expression would yield the string "-foo-foo-foo-".

Invoking this method changes this matcher's state. If the matcher
is to be used in further matching operations then it should first be
reset.

<br />

##### Parameters

| replacement | The replacement string |
|---|---|

##### Returns

- The string constructed by replacing each matching subsequence by the replacement string, substituting captured subsequences as needed

#### public [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**replaceFirst**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) replacement)

Replaces the first subsequence of the input sequence that matches the
pattern with the given replacement string.

This method first resets this matcher. It then scans the input
sequence looking for a match of the pattern. Characters that are not
part of the match are appended directly to the result string; the match
is replaced in the result by the replacement string. The replacement
string may contain references to captured subsequences as in the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#appendReplacement(java.lang.StringBuffer,%20java.lang.String)` method.

Note that backslashes (\\) and dollar signs ($) in
the replacement string may cause the results to be different than if it
were being treated as a literal replacement string. Dollar signs may be
treated as references to captured subsequences as described above, and
backslashes are used to escape literal characters in the replacement
string.

Given the regular expression dog, the input
"zzzdogzzzdogzzz", and the replacement string
"cat", an invocation of this method on a matcher for that
expression would yield the string "zzzcatzzzdogzzz".

Invoking this method changes this matcher's state. If the matcher
is to be used in further matching operations then it should first be
reset.

<br />

##### Parameters

| replacement | The replacement string |
|---|---|

##### Returns

- The string constructed by replacing the first matching subsequence by the replacement string, substituting captured subsequences as needed

#### public boolean
**requireEnd**
()

<br />

Returns true if more input could change a positive match into a
negative one.

If this method returns true, and a match was found, then more
input could cause the match to be lost. If this method returns false
and a match was found, then more input might change the match but the
match won't be lost. If a match was not found, then requireEnd has no
meaning.

##### Returns

- true iff more input could change a positive match into a negative one.

#### public [Matcher](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html)
**reset**
([CharSequence](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/CharSequence.html) input)

Resets this matcher with a new input sequence.

Resetting a matcher discards all of its explicit state information
and sets its append position to zero. The matcher's region is set to
the default region, which is its entire character sequence. The
anchoring and transparency of this matcher's region boundaries are
unaffected.

##### Parameters

| input | The new input character sequence |
|---|---|

##### Returns

- This matcher

#### public [Matcher](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html)
**reset**
()

Resets this matcher.

Resetting a matcher discards all of its explicit state information
and sets its append position to zero. The matcher's region is set to the
default region, which is its entire character sequence. The anchoring
and transparency of this matcher's region boundaries are unaffected.

##### Returns

- This matcher

#### public int
**start**
()

Returns the start index of the previous match.

##### Returns

- The index of the first character matched

##### Throws

| [IllegalStateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | If no match has yet been attempted, or if the previous match operation failed |
|---|---|

#### public int
**start**
(int group)

Returns the start index of the subsequence captured by the given group
during the previous match operation.

[Capturing groups](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Pattern#cg) are indexed from left
to right, starting at one. Group zero denotes the entire pattern, so
the expression *m.*start(0) is equivalent to
*m.*start().

<br />

##### Parameters

| group | The index of a capturing group in this matcher's pattern |
|---|---|

##### Returns

- The index of the first character captured by the group, or -1 if the match was successful but the group itself did not match anything

##### Throws

| [IllegalStateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | If no match has yet been attempted, or if the previous match operation failed |
| [IndexOutOfBoundsException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IndexOutOfBoundsException.html) | If there is no capturing group in the pattern with the given index |
|---|---|

#### public int
**start**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) name)

Returns the start index of the subsequence captured by the given
[named-capturing group](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Pattern#groupname) during the
previous match operation.

##### Parameters

| name | The name of a named-capturing group in this matcher's pattern |
|---|---|

##### Returns

- The index of the first character captured by the group, or `-1` if the match was successful but the group itself did not match anything

##### Throws

| [IllegalStateException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalStateException.html) | If no match has yet been attempted, or if the previous match operation failed |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | If there is no capturing group in the pattern with the given name |
|---|---|

#### public [MatchResult](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/MatchResult.html)
**toMatchResult**
()

Returns the match state of this matcher as a `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/MatchResult.html`.
The result is unaffected by subsequent operations performed upon this
matcher.

##### Returns

- a `MatchResult` with the state of this matcher

#### public [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**toString**
()

<br />

Returns the string representation of this matcher. The
string representation of a `Matcher` contains information
that may be useful for debugging. The exact format is unspecified.

##### Returns

- The string representation of this matcher

#### public [Matcher](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html)
**useAnchoringBounds**
(boolean b)

Sets the anchoring of region bounds for this matcher.

Invoking this method with an argument of true will set this
matcher to use *anchoring* bounds. If the boolean
argument is false, then *non-anchoring* bounds will be
used.

Using anchoring bounds, the boundaries of this
matcher's region match anchors such as \^ and $.

Without anchoring bounds, the boundaries of this
matcher's region will not match anchors such as \^ and $.

By default, a matcher uses anchoring region boundaries.

##### Parameters

| b | a boolean indicating whether or not to use anchoring bounds. |
|---|---|

##### Returns

- this matcher

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#hasAnchoringBounds()`

#### public [Matcher](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html)
**usePattern**
([Pattern](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Pattern.html) newPattern)

Changes the Pattern that this Matcher uses to
find matches with.

This method causes this matcher to lose information
about the groups of the last match that occurred. The
matcher's position in the input is maintained and its
last append position is unaffected.

<br />

##### Parameters

| newPattern | The new pattern used by this matcher |
|---|---|

##### Returns

- This matcher

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | If newPattern is null |
|---|---|

#### public [Matcher](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html)
**useTransparentBounds**
(boolean b)

Sets the transparency of region bounds for this matcher.

Invoking this method with an argument of true will set this
matcher to use *transparent* bounds. If the boolean
argument is false, then *opaque* bounds will be used.

Using transparent bounds, the boundaries of this
matcher's region are transparent to lookahead, lookbehind,
and boundary matching constructs. Those constructs can see beyond the
boundaries of the region to see if a match is appropriate.

Using opaque bounds, the boundaries of this matcher's
region are opaque to lookahead, lookbehind, and boundary matching
constructs that may try to see beyond them. Those constructs cannot
look past the boundaries so they will fail to match anything outside
of the region.

By default, a matcher uses opaque bounds.

##### Parameters

| b | a boolean indicating whether to use opaque or transparent regions |
|---|---|

##### Returns

- this matcher

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/regex/Matcher.html#hasTransparentBounds()`

## Protected Methods

#### protected void
**finalize**
()

Invoked when the garbage collector has detected that this instance is no longer reachable.
The default implementation does nothing, but this method can be overridden to free resources.

Note that objects that override `finalize` are significantly more expensive than
objects that don't. Finalizers may be run a long time after the object is no longer
reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup.
Note also that finalizers are run on a single VM-wide finalizer thread,
so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary
for a class that has a native peer and needs to call a native method to destroy that peer.
Even then, it's better to provide an explicit `close` method (and implement
`https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Closeable.html`), and insist that callers manually dispose of instances. This
works well for something like files, but less well for something like a `BigInteger`
where typical calling code would have to deal with lots of temporaries. Unfortunately,
code that creates lots of temporaries is the worst kind of code from the point of view of
the single finalizer thread.

If you *must* use finalizers, consider at least providing your own
`https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ref/ReferenceQueue.html` and having your own thread process that queue.

Unlike constructors, finalizers are not automatically chained. You are responsible for
calling `super.finalize()` yourself.

Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer
thread.

See *Effective Java* Item 7, "Avoid finalizers" for more.

##### Throws

| [Throwable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html) |   |
|---|---|