Package: java.util.regex

## [Java] Class Matcher

- java.util.regex.Matcher

-     public class Matcher
      extends Object

  GDK enhancements for Matcher.

  displayName:
    Matcher
  receiverFqcn:
    java.util.regex.Matcher

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public boolean` | `asBoolean()` Coerces a Matcher instance to a boolean value.
    `` | `public List` | `getAt(Collection indices)` Selects a List of values from a Matcher using a Collection to identify the indices to be selected.
    `` | `public Object` | `getAt(int index)` Supports the subscript operator, e.g.
    `` | `public int` | `getCount()` Finds the number of Strings matched to the given Matcher.
    `` | `public static Matcher` | `getLastMatcher(Matcher self)` Get the last hidden matcher that the system used to do a match.
    `` | `public boolean` | `hasGroup()` Checks whether a Matcher contains a group or not.
    `` | `public Iterator` | `iterator()` Returns an Iterator which traverses each match.
    `` | `public boolean` | `matchesPartially()` Given a matcher that matches a string against a pattern, returns true when the string matches the pattern or if a longer string, could match the pattern.
    `` | `public void` | `setIndex(int index)` Sets the position of the given Matcher to the given index.
    `` | `public long` | `size()` Provides the standard Groovy `size()` method for `Matcher`.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `addShutdownHook, any, any, asBoolean, asType, clamp, clamp, collect, collect, collect, dump, each, eachMatch, eachMatch, eachWithIndex, every, every, find, find, findAll, findAll, findIndexOf, findIndexOf, findIndexValues, findIndexValues, findLastIndexOf, findLastIndexOf, findResult, findResult, findResult, findResult, getAt, getMetaClass, getMetaPropertyValues, getProperties, grep, grep, hasProperty, identity, inject, inject, inspect, invokeMethod, is, isCase, isNotCase, iterator, metaClass, print, print, printf, printf, println, println, println, putAt, respondsTo, respondsTo, setMetaClass, sleep, sleep, split, sprintf, sprintf, stream, takeIf, tap, toString, use, use, use, with, with, withCloseable, withCloseable, withMethodClosure, withStream, withStream, withTraits`

- - ### Method Detail

    - #### public boolean asBoolean()

      Coerces a Matcher instance to a boolean value.

      Returns:
        the boolean value
      Since:
        1.7.0

    - #### public List getAt(Collection indices)

      Selects a List of values from a Matcher using a Collection to identify the indices to be selected.

      Parameters:
        `indices` - a Collection of indices
      Returns:
        a String of the values at the given indices
      Since:
        1.6.0

    - #### public Object getAt(int index)

      Supports the subscript operator, e.g. `matcher[index]`, for a `Matcher`.

      For an example using no group match,

              def p = /ab[d|f]/
              def m = "abcabdabeabf" =~ p
              assert 2 == m.count
              assert 2 == m.size() // synonym for m.getCount()
              assert ! m.hasGroup()
              assert 0 == m.groupCount()
              def matches = ["abd", "abf"]
              for (i in 0..<m.count) {
                assert m[i] == matches[i]
              }

      For an example using group matches,

              def p = /(?:ab([c|d|e|f]))/
              def m = "abcabdabeabf" =~ p
              assert 4 == m.count
              assert m.hasGroup()
              assert 1 == m.groupCount()
              def matches = [["abc", "c"], ["abd", "d"], ["abe", "e"], ["abf", "f"]]
              for (i in 0..<m.count) {
                assert m[i] == matches[i]
              }

      For another example using group matches,

              def m = "abcabdabeabfabxyzabx" =~ /(?:ab([d|x-z]+))/
              assert 3 == m.count
              assert m.hasGroup()
              assert 1 == m.groupCount()
              def matches = [["abd", "d"], ["abxyz", "xyz"], ["abx", "x"]]
              for (i in 0..<m.count) {
                assert m[i] == matches[i]
              }

      Parameters:
        `index` - an index
      Returns:
        object a matched String if no groups matched, list of matched groups otherwise.
      Since:
        1.0

    - #### public int getCount()

      Finds the number of Strings matched to the given Matcher.

      Returns:
        int the number of Strings matched to the given matcher.
      Since:
        1.0

    - #### public static Matcher getLastMatcher(Matcher self)

      Get the last hidden matcher that the system used to do a match.

      Parameters:
        `self` - placeholder variable used by Groovy categories; ignored for default static methods
      Returns:
        the last regex matcher
      Since:
        1.0

    - #### public boolean hasGroup()

      Checks whether a Matcher contains a group or not.

      Returns:
        boolean `true` if matcher contains at least one group.
      Since:
        1.0

    - #### public Iterator iterator()

      Returns an Iterator which traverses each match.

      Returns:
        an Iterator for a Matcher
      Since:
        1.0
      See Also:
        Matcher.group

    - #### public boolean matchesPartially()

      Given a matcher that matches a string against a pattern, returns true when the string matches the pattern or if a longer string, could match the pattern. For example:

               def emailPattern = /\w+@\w+\.\w{2,}/

               def matcher = "john@doe" =~ emailPattern
               assert matcher.matchesPartially()

               matcher = "john@doe.com" =~ emailPattern
               assert matcher.matchesPartially()

               matcher = "john@@" =~ emailPattern
               assert !matcher.matchesPartially()

      Returns:
        true if more input to the String could make the matcher match the associated pattern, false otherwise.
      Since:
        2.0.0

    - #### public void setIndex(int index)

      Sets the position of the given Matcher to the given index.

      Parameters:
        `index` - the index number
      Since:
        1.0

    - #### public long size()

      Provides the standard Groovy `size()` method for `Matcher`.

      Returns:
        the matcher's size (count)
      Since:
        1.5.0