Newer Version Available
Matcher Class
Namespace
Matcher Methods
The following are methods for Matcher.
end()
Signature
public Integer end()
Return Value
Type: Integer
end(groupIndex)
Signature
public Integer end(Integer groupIndex)
Parameters
- groupIndex
- Type: Integer
Return Value
Type: Integer
find()
Signature
public Boolean find()
Return Value
Type: Boolean
Usage
This method starts at the beginning of this Matcher object's region, or, if a previous invocation of the method was successful and the Matcher object has not since been reset, at the first character not matched by the previous match.
If the match succeeds, more information can be obtained using the start, end, and group methods.
For more information, see Using Regions.
find(group)
Signature
public Boolean find(Integer group)
Parameters
- group
- Type: Integer
Return Value
Type: Boolean
Usage
If the match succeeds, more information can be obtained using the start, end, and group methods.
group()
Signature
public String group()
Return Value
Type: String
group(groupIndex)
Signature
public String group(Integer groupIndex)
Parameters
- groupIndex
- Type: Integer
Return Value
Type: String
Usage
Captured groups 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().
Note that some groups, such as (a*), match the empty string. This method returns the empty string when such a group successfully matches the empty string in the input.
groupCount()
Signature
public Integer groupCount()
Return Value
Type: Integer
Usage
hasAnchoringBounds()
Signature
public Boolean hasAnchoringBounds()
Return Value
Type: Boolean
Usage
If a Matcher object uses anchoring bounds, the boundaries of this Matcher object's region match start and end of line anchors such as ^ and $.
For more information, see Using Bounds.
hasTransparentBounds()
Signature
public Boolean hasTransparentBounds()
Return Value
Type: Boolean
Usage
For more information, see Using Bounds.
hitEnd()
Signature
public Boolean hitEnd()
Return Value
Type: Boolean
lookingAt()
Signature
public Boolean lookingAt()
Return Value
Type: Boolean
Usage
Like the matches method, this method always starts at the beginning of the region; unlike that method, it does not require the entire region be matched.
If the match succeeds, more information can be obtained using the start, end, and group methods.
See Using Regions.
matches()
Signature
public Boolean matches()
Return Value
Type: Boolean
Usage
If the match succeeds, more information can be obtained using the start, end, and group methods.
See Using Regions.
pattern()
Signature
public Pattern object pattern()
Return Value
Type: System.Pattern
quoteReplacement(inputString)
region(start, end)
Signature
public Matcher object region(Integer start, Integer end)
Return Value
Type: Matcher
Usage
This method first resets the Matcher object, then sets the region to start at the index specified by start and end at the index specified by end.
Depending on the transparency boundaries being used, certain constructs such as anchors may behave differently at or around the boundaries of the region.
See Using Regions and Using Bounds.
regionEnd()
Signature
public Integer regionEnd()
Return Value
Type: Integer
Usage
See Using Regions.
regionStart()
Signature
public Integer regionStart()
Return Value
Type: Integer
Usage
See Using Regions.
replaceAll(replacementString)
Signature
public String replaceAll(String replacementString)
Parameters
- replacementString
- Type: String
Return Value
Type: String
Usage
This method first resets the Matcher object, 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.
Note that backslashes (\) and dollar signs ($) in the replacement string may cause the results to be different than if the string was treated as a literal replacement string. Dollar signs may be treated as references to captured subsequences, and backslashes are used to escape literal characters in the replacement string.
Invoking this method changes this Matcher object's state. If the Matcher object is to be used in further matching operations it should first be reset.
Given the regular expression a*b, the input "aabxyzaabxyzabxyzb", and the replacement string "-", an invocation of this method on a Matcher object for that expression would yield the string "-xyz-xyz-xyz-".
replaceFirst(replacementString)
Signature
public String replaceFirst(String replacementString)
Parameters
- replacementString
- Type: String
Return Value
Type: String
Usage
Note that backslashes (\) and dollar signs ($) in the replacement string may cause the results to be different than if the string was treated as a literal replacement string. Dollar signs may be treated as references to captured subsequences, and backslashes are used to escape literal characters in the replacement string.
Invoking this method changes this Matcher object's state. If the Matcher object is to be used in further matching operations it should first be reset.
Given the regular expression dog, the input "zzzdogzzzdogzzz", and the replacement string "cat", an invocation of this method on a Matcher object for that expression would return the string "zzzcatzzzdogzzz".
requireEnd()
Signature
public Boolean requireEnd()
Return Value
Type: Boolean
Usage
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.
reset()
Signature
public Matcher object reset()
Return Value
Type: Matcher
Usage
This method does not change whether the Matcher object uses anchoring bounds. You must explicitly use the useAnchoringBounds method to change the anchoring bounds.
For more information, see Using Bounds.
start()
Signature
public Integer start()
Return Value
Type: Integer
start(groupIndex)
Signature
public Integer start(Integer groupIndex)
Parameters
- groupIndex
- Type: Integer
Return Value
Type: Integer
Usage
useAnchoringBounds(anchoringBounds)
Signature
public Matcher object useAnchoringBounds(Boolean anchoringBounds)
Parameters
- anchoringBounds
- Type: Boolean
- If you specify true, the Matcher object uses anchoring bounds. If you specify false, non-anchoring bounds are used.
Return Value
Type: Matcher
Usage
If a Matcher object uses anchoring bounds, the boundaries of this Matcher object's region match start and end of line anchors such as ^ and $.
For more information, see Using Bounds.
usePattern(pattern)
Signature
public Matcher object usePattern(Pattern pattern)
Parameters
- pattern
- Type: System.Pattern
Return Value
Type: Matcher
useTransparentBounds(transparentBounds)
Signature
public Matcher object useTransparentBounds(Boolean transparentBounds)
Parameters
- transparentBounds
- Type: Boolean
- If you specify true, the Matcher object uses transparent bounds. If you specify false, opaque bounds are used.
Return Value
Type: Matcher
Usage
For more information, see Using Bounds.