Return type | Name and parameters |
---|---|
boolean
|
asBoolean()
Coerces a Matcher instance to a boolean value. |
Object
|
getAt(int index)
Supports the subscript operator, e.g. |
List
|
getAt(Collection indices)
Selects a List of values from a Matcher using a Collection to identify the indices to be selected. |
int
|
getCount()
Finds the number of Strings matched to the given Matcher. |
static Matcher
|
getLastMatcher()
Get the last hidden matcher that the system used to do a match. |
boolean
|
hasGroup()
Checks whether a Matcher contains a group or not. |
Iterator
|
iterator()
Returns an Iterator which traverses each match. |
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. |
void
|
setIndex(int index)
Sets the position of the given Matcher to the given index. |
long
|
size()
Provides the standard Groovy size() method for Matcher .
|
addShutdownHook
, any
, any
, asBoolean
, asType
, 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
, split
, sprintf
, sprintf
, stream
, tap
, toString
, use
, use
, use
, with
, with
, withCloseable
, withMethodClosure
, withStream
, withTraits
Coerces a Matcher instance to a boolean value.
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] }
index
- an indexSelects a List of values from a Matcher using a Collection to identify the indices to be selected.
indices
- a Collection of indicesFinds the number of Strings matched to the given Matcher.
Get the last hidden matcher that the system used to do a match.
Checks whether a Matcher contains a group or not.
true
if matcher contains at least one group.Returns an Iterator which traverses each match.
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()
Sets the position of the given Matcher to the given index.
index
- the index numberProvides the standard Groovy size()
method for Matcher
.