Overview | Package | Class | Tree | Deprecated | Index | Help
| Groovy JDK

## java.util.regex
Class Matcher

Method Summary
`Matcher` | `each(Closure closure)` Process each matched substring of the given group matcher passed to the closure is an array of strings, matched per a successful match
`Object` | `getAt(int idx)` Support the subscript operator, e For an example using no group match, `
    def p = /ab[d|f]/
    def m = "abcabdabeabf" =~ p
    for (i in 0
    println( "m
    println( " " + i + ": " + m[i] ) // m[i] is a String
    }
` For an example using group matches, `
    def p = /(?:ab([c|d|e|f]))/
    def m = "abcabdabeabf" =~ p
    for (i in 0
    println( "m
    println( " " + i + ": " + m[i] ) // m[i] is a List
    }
` For another example using group matches, `
    def m = "abcabdabeabfabxyzabx" =~ /(?:ab([d|x-z]+))/
    m
    println( "m
    println( " " + it + ": " + m[it] ) // m[it] is a List
    }
`
`String` | `getAt(Collection indices)` Allows a List to be used as the indices to be used on a Matcher
`int` | `getCount()` Find the number of Strings matched to the given Matcher
`static Matcher` | `getLastMatcher()` Get the last hidden matcher that system used to do a match
`boolean` | `hasGroup()` Check whether a Matcher contains a group or not
`Iterator` | `iterator()` Retuns an {@link Iterator} which traverses each match
`void` | `setIndex(int idx)` Set the position of the given Matcher to the given index
`long` | `size()` Provide the standard Groovy `size()` method for `Matcher`

Method Detail

### each

    public Matcher each(Closure closure)

  Process each matched substring of the given group matcher. The object passed to the closure is an array of strings, matched per a successful match.

Parameters:
  `closure` - a closure.
Returns:
  the matcher

### getAt

    public Object getAt(int idx)

  Support the subscript operator, e.g. matcher[index], for a regex Matcher.

  For an example using no group match, `

      def p = /ab[d|f]/
      def m = "abcabdabeabf" =~ p
      for (i in 0..

  `

  For an example using group matches, `

      def p = /(?:ab([c|d|e|f]))/
      def m = "abcabdabeabf" =~ p
      for (i in 0..

  `

  For another example using group matches, `

      def m = "abcabdabeabfabxyzabx" =~ /(?:ab([d|x-z]+))/
      m.count.times {
      println( "m.groupCount() = " + m.groupCount())
      println( " " + it + ": " + m[it] ) // m[it] is a List
      }

  `

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

### getAt

    public String getAt(Collection indices)

  Allows a List to be used as the indices to be used on a Matcher

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

### getCount

    public int getCount()

  Find the number of Strings matched to the given Matcher.

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

### getLastMatcher

    public static Matcher getLastMatcher()

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

Returns:
  the last regex matcher

### hasGroup

    public boolean hasGroup()

  Check whether a Matcher contains a group or not.

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

### iterator

    public Iterator iterator()

  Retuns an {@link Iterator} which traverses each match.

Returns:
  an Iterator for a Matcher

See:
  Matcher#group().

### setIndex

    public void setIndex(int idx)

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

Parameters:
  `idx` - the index number.

### size

    public long size()

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

Returns:
  the matcher's size (count)

Overview | Package | Class | Tree | Deprecated | Index | Help
| Groovy JDK