Java Doc for Matcher.java in  » 6.0-JDK-Core » Collections-Jar-Zip-Logging-regex » java » util » regex » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » Collections Jar Zip Logging regex » java.util.regex 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.util.regex.Matcher

Matcher
final public class Matcher implements MatchResult(Code)
An engine that performs match operations on a java.lang.CharSequencecharacter sequence by interpreting a Pattern .

A matcher is created from a pattern by invoking the pattern's Pattern.matcher matcher method. Once created, a matcher can be used to perform three different kinds of match operations:

  • The Matcher.matches matches method attempts to match the entire input sequence against the pattern.

  • The Matcher.lookingAt lookingAt method attempts to match the input sequence, starting at the beginning, against the pattern.

  • The Matcher.find find method scans the input sequence looking for the next subsequence that matches the pattern.

Each of these methods returns a boolean indicating success or failure. More information about a successful match can be obtained by querying the state of the matcher.

A matcher finds matches in a subset of its input called the region. By default, the region contains all of the matcher's input. The region can be modified via the Matcher.region region method and queried via the Matcher.regionStart regionStart and Matcher.regionEnd regionEnd methods. The way that the region boundaries interact with some pattern constructs can be changed. See Matcher.useAnchoringBounds useAnchoringBounds and Matcher.useTransparentBounds useTransparentBounds for more details.

This class also defines methods for replacing matched subsequences with new strings whose contents can, if desired, be computed from the match result. The Matcher.appendReplacement appendReplacement and Matcher.appendTail appendTail methods can be used in tandem in order to collect the result into an existing string buffer, or the more convenient Matcher.replaceAll replaceAll method can be used to create a string in which every matching subsequence in the input sequence is replaced.

The explicit state of a matcher includes the start and end indices of the most recent successful match. It also includes the start and end indices of the input subsequence captured by each capturing group in the pattern as well as a total count of such subsequences. As a convenience, methods are also provided for returning these captured subsequences in string form.

The explicit state of a matcher is initially undefined; attempting to query any part of it before a successful match will cause an IllegalStateException to be thrown. The explicit state of a matcher is recomputed by every match operation.

The implicit state of a matcher includes the input character sequence as well as the append position, which is initially zero and is updated by the Matcher.appendReplacement appendReplacement method.

A matcher may be reset explicitly by invoking its Matcher.reset() method or, if a new input sequence is desired, its Matcher.reset(java.lang.CharSequence) reset(CharSequence) method. Resetting a matcher discards its explicit state information and sets the append position to zero.

Instances of this class are not safe for use by multiple concurrent threads.


author:
   Mike McCloskey
author:
   Mark Reinhold
author:
   JSR-51 Expert Group
version:
   1.73, 07/05/05
since:
   1.4


Field Summary
final static  intENDANCHOR
     Matcher state used by the last node.
final static  intNOANCHOR
    
 intacceptMode
    
 booleananchoringBounds
     If anchoringBounds is true then the boundaries of this matcher's region match anchors such as ^ and $.
 intfirstlast
     The range of string that last matched the pattern.
 intfromto
     The range within the sequence that is to be matched.
 int[]groups
     The storage used by groups.
 booleanhitEnd
     Boolean indicating whether or not more input could change the results of the last match.
 intlastAppendPosition
     The index of the last position appended in a substitution.
 int[]locals
     Storage used by nodes to tell what repetition they are on in a pattern, and where groups begin.
 intlookbehindTo
     Lookbehind uses this value to ensure that the subexpression match ends at the point where the lookbehind was encountered.
 intoldLast
     The end index of what matched in the last match operation.
 PatternparentPattern
     The Pattern object that created this Matcher.
 booleanrequireEnd
     Boolean indicating whether or not more input could change a positive match into a negative one.
 CharSequencetext
     The original string being matched.
 booleantransparentBounds
     If transparentBounds is true then the boundaries of this matcher's region are transparent to lookahead, lookbehind, and boundary matching constructs that try to see beyond them.

Constructor Summary
 Matcher()
     No default constructor.
 Matcher(Pattern parent, CharSequence text)
     All matchers have the state used by Pattern during a match.

Method Summary
public  MatcherappendReplacement(StringBuffer sb, String 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.

public  StringBufferappendTail(StringBuffer 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.

 charcharAt(int i)
     Returns this Matcher's input character at index i.
public  intend()
     Returns the offset after the last character matched.
public  intend(int group)
     Returns the offset after the last character of the subsequence captured by the given group during the previous match operation.

Capturing groups are indexed from left to right, starting at one.

public  booleanfind()
     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.

public  booleanfind(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 Matcher.find() method will start at the first character not matched by this match.

 CharSequencegetSubSequence(int beginIndex, int endIndex)
     Generates a String from this Matcher's input in the specified range.
 intgetTextLength()
     Returns the end index of the text.
public  Stringgroup()
     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.

public  Stringgroup(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.

public  intgroupCount()
     Returns the number of capturing groups in this matcher's pattern.

Group zero denotes the entire pattern by convention.

public  booleanhasAnchoringBounds()
     Queries the anchoring of region bounds for this matcher.
public  booleanhasTransparentBounds()
     Queries the transparency of region bounds for this matcher.
public  booleanhitEnd()
    

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

public  booleanlookingAt()
     Attempts to match the input sequence, starting at the beginning of the region, against the pattern.

Like the Matcher.matches 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.

 booleanmatch(int from, int anchor)
     Initiates a search for an anchored match to a Pattern within the given bounds.
public  booleanmatches()
     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.

public  Patternpattern()
     Returns the pattern that is interpreted by this matcher.
public static  StringquoteReplacement(String 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 Matcher class. The String produced will match the sequence of characters in s treated as a literal sequence.
public  Matcherregion(int start, int end)
     Sets the limits of this matcher's region.
public  intregionEnd()
     Reports the end index (exclusive) of this matcher's region.
public  intregionStart()
     Reports the start index of this matcher's region.
public  StringreplaceAll(String replacement)
     Replaces every subsequence of the input sequence that matches the pattern with the given replacement string.

This method first resets this matcher.

public  StringreplaceFirst(String replacement)
     Replaces the first subsequence of the input sequence that matches the pattern with the given replacement string.

This method first resets this matcher.

public  booleanrequireEnd()
    

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.

public  Matcherreset()
     Resets this matcher.

Resetting a matcher discards all of its explicit state information and sets its append position to zero.

public  Matcherreset(CharSequence 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.

 booleansearch(int from)
     Initiates a search to find a Pattern within the given bounds. The groups are filled with default values and the match of the root of the state machine is called.
public  intstart()
     Returns the start index of the previous match.
public  intstart(int group)
     Returns the start index of the subsequence captured by the given group during the previous match operation.

Capturing groups are indexed from left to right, starting at one.

public  MatchResulttoMatchResult()
     Returns the match state of this matcher as a MatchResult .
public  StringtoString()
    

Returns the string representation of this matcher.

public  MatcheruseAnchoringBounds(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.

public  MatcherusePattern(Pattern 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.

public  MatcheruseTransparentBounds(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.


Field Detail
ENDANCHOR
final static int ENDANCHOR(Code)
Matcher state used by the last node. NOANCHOR is used when a match does not have to consume all of the input. ENDANCHOR is the mode used for matching all the input.



NOANCHOR
final static int NOANCHOR(Code)



acceptMode
int acceptMode(Code)



anchoringBounds
boolean anchoringBounds(Code)
If anchoringBounds is true then the boundaries of this matcher's region match anchors such as ^ and $.



firstlast
int firstlast(Code)
The range of string that last matched the pattern. If the last match failed then first is -1; last initially holds 0 then it holds the index of the end of the last match (which is where the next search starts).



fromto
int fromto(Code)
The range within the sequence that is to be matched. Anchors will match at these "hard" boundaries. Changing the region changes these values.



groups
int[] groups(Code)
The storage used by groups. They may contain invalid values if a group was skipped during the matching.



hitEnd
boolean hitEnd(Code)
Boolean indicating whether or not more input could change the results of the last match. If hitEnd is true, and a match was found, then more input might cause a different match to be found. If hitEnd is true and a match was not found, then more input could cause a match to be found. If hitEnd is false and a match was found, then more input will not change the match. If hitEnd is false and a match was not found, then more input will not cause a match to be found.



lastAppendPosition
int lastAppendPosition(Code)
The index of the last position appended in a substitution.



locals
int[] locals(Code)
Storage used by nodes to tell what repetition they are on in a pattern, and where groups begin. The nodes themselves are stateless, so they rely on this field to hold state during a match.



lookbehindTo
int lookbehindTo(Code)
Lookbehind uses this value to ensure that the subexpression match ends at the point where the lookbehind was encountered.



oldLast
int oldLast(Code)
The end index of what matched in the last match operation.



parentPattern
Pattern parentPattern(Code)
The Pattern object that created this Matcher.



requireEnd
boolean requireEnd(Code)
Boolean indicating whether or not more input could change a positive match into a negative one. If requireEnd is true, and a match was found, then more input could cause the match to be lost. If requireEnd is 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.



text
CharSequence text(Code)
The original string being matched.



transparentBounds
boolean transparentBounds(Code)
If transparentBounds is true then the boundaries of this matcher's region are transparent to lookahead, lookbehind, and boundary matching constructs that try to see beyond them.




Constructor Detail
Matcher
Matcher()(Code)
No default constructor.



Matcher
Matcher(Pattern parent, CharSequence text)(Code)
All matchers have the state used by Pattern during a match.




Method Detail
appendReplacement
public Matcher appendReplacement(StringBuffer sb, String replacement)(Code)
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 Matcher.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 Matcher.end() .

The replacement string may contain references to subsequences captured during the previous match: Each occurrence of $g will be replaced by the result of evaluating Matcher.group(int) group (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 Matcher.appendTail appendTail and Matcher.find 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());

Parameters:
  sb - The target string buffer
Parameters:
  replacement - The replacement string This matcher
throws:
  IllegalStateException - If no match has yet been attempted,or if the previous match operation failed
throws:
  IndexOutOfBoundsException - If the replacement string refers to a capturing groupthat does not exist in the pattern



appendTail
public StringBuffer appendTail(StringBuffer sb)(Code)
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 Matcher.appendReplacement appendReplacement method in order to copy the remainder of the input sequence.


Parameters:
  sb - The target string buffer The target string buffer



charAt
char charAt(int i)(Code)
Returns this Matcher's input character at index i. A char from the specified index



end
public int end()(Code)
Returns the offset after the last character matched.

The offset after the last character matched
throws:
  IllegalStateException - If no match has yet been attempted,or if the previous match operation failed



end
public int end(int group)(Code)
Returns the offset after the last character of the subsequence captured by the given group during the previous match operation.

Capturing groups 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().


Parameters:
  group - The index of a capturing group in this matcher's pattern The offset after the last character captured by the group,or -1 if the match was successfulbut the group itself did not match anything
throws:
  IllegalStateException - If no match has yet been attempted,or if the previous match operation failed
throws:
  IndexOutOfBoundsException - If there is no capturing group in the patternwith the given index



find
public boolean find()(Code)
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.

true if, and only if, a subsequence of the inputsequence matches this matcher's pattern



find
public boolean find(int start)(Code)
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 Matcher.find() method will start at the first character not matched by this match.


throws:
  IndexOutOfBoundsException - If start is less than zero or if start is greater than thelength of the input sequence. true if, and only if, a subsequence of the inputsequence starting at the given index matches this matcher'spattern



getSubSequence
CharSequence getSubSequence(int beginIndex, int endIndex)(Code)
Generates a String from this Matcher's input in the specified range.
Parameters:
  beginIndex - the beginning index, inclusive
Parameters:
  endIndex - the ending index, exclusive A String generated from this Matcher's input



getTextLength
int getTextLength()(Code)
Returns the end index of the text. the index after the last character in the text



group
public String group()(Code)
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.

The (possibly empty) subsequence matched by the previous match,in string form
throws:
  IllegalStateException - If no match has yet been attempted,or if the previous match operation failed



group
public String group(int group)(Code)
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 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.


Parameters:
  group - The index of a capturing group in this matcher's pattern The (possibly empty) subsequence captured by the groupduring the previous match, or null if the groupfailed to match part of the input
throws:
  IllegalStateException - If no match has yet been attempted,or if the previous match operation failed
throws:
  IndexOutOfBoundsException - If there is no capturing group in the patternwith the given index



groupCount
public int groupCount()(Code)
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.

The number of capturing groups in this matcher's pattern



hasAnchoringBounds
public boolean hasAnchoringBounds()(Code)
Queries the anchoring of region bounds for this matcher.

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

See Matcher.useAnchoringBounds useAnchoringBounds for a description of anchoring bounds.

By default, a matcher uses anchoring region boundaries. true iff this matcher is using anchoring bounds,false otherwise.
See Also:   java.util.regex.Matcher.useAnchoringBounds(boolean)
since:
   1.5




hasTransparentBounds
public boolean hasTransparentBounds()(Code)
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 Matcher.useTransparentBounds useTransparentBounds for a description of transparent and opaque bounds.

By default, a matcher uses opaque region boundaries. true iff this matcher is using transparent bounds,false otherwise.
See Also:   java.util.regex.Matcher.useTransparentBounds(boolean)
since:
   1.5




hitEnd
public boolean hitEnd()(Code)

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. true iff the end of input was hit in the last match; falseotherwise
since:
   1.5




lookingAt
public boolean lookingAt()(Code)
Attempts to match the input sequence, starting at the beginning of the region, against the pattern.

Like the Matcher.matches 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.

true if, and only if, a prefix of the inputsequence matches this matcher's pattern



match
boolean match(int from, int anchor)(Code)
Initiates a search for an anchored match to a Pattern within the given bounds. The groups are filled with default values and the match of the root of the state machine is called. The state machine will hold the state of the match as it proceeds in this matcher.



matches
public boolean matches()(Code)
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.

true if, and only if, the entire region sequencematches this matcher's pattern



pattern
public Pattern pattern()(Code)
Returns the pattern that is interpreted by this matcher. The pattern for which this matcher was created



quoteReplacement
public static String quoteReplacement(String s)(Code)
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 Matcher 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 A literal string replacement
since:
   1.5



region
public Matcher region(int start, int end)(Code)
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 Matcher.useTransparentBounds useTransparentBounds and Matcher.useAnchoringBounds useAnchoringBounds ), 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)
Parameters:
  end - The index to end searching at (exclusive)
throws:
  IndexOutOfBoundsException - If start or end is less than zero, ifstart is greater than the length of the input sequence, ifend is greater than the length of the input sequence, or ifstart is greater than end. this matcher
since:
   1.5




regionEnd
public int regionEnd()(Code)
Reports the end index (exclusive) of this matcher's region. The searches this matcher conducts are limited to finding matches within Matcher.regionStart regionStart (inclusive) and Matcher.regionEnd regionEnd (exclusive). the ending point of this matcher's region
since:
   1.5



regionStart
public int regionStart()(Code)
Reports the start index of this matcher's region. The searches this matcher conducts are limited to finding matches within Matcher.regionStart regionStart (inclusive) and Matcher.regionEnd regionEnd (exclusive). The starting point of this matcher's region
since:
   1.5



replaceAll
public String replaceAll(String replacement)(Code)
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 Matcher.appendReplacement appendReplacement 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.


Parameters:
  replacement - The replacement string The string constructed by replacing each matching subsequenceby the replacement string, substituting captured subsequencesas needed



replaceFirst
public String replaceFirst(String replacement)(Code)
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 Matcher.appendReplacement appendReplacement 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.


Parameters:
  replacement - The replacement string The string constructed by replacing the first matchingsubsequence by the replacement string, substituting capturedsubsequences as needed



requireEnd
public boolean requireEnd()(Code)

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. true iff more input could change a positive match into a negative one.
since:
   1.5




reset
public Matcher reset()(Code)
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. This matcher




reset
public Matcher reset(CharSequence input)(Code)
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 This matcher




search
boolean search(int from)(Code)
Initiates a search to find a Pattern within the given bounds. The groups are filled with default values and the match of the root of the state machine is called. The state machine will hold the state of the match as it proceeds in this matcher. Matcher.from is not set here, because it is the "hard" boundary of the start of the search which anchors will set to. The from param is the "soft" boundary of the start of the search, meaning that the regex tries to match at that index but ^ won't match there. Subsequent calls to the search methods start at a new "soft" boundary which is the end of the previous match.



start
public int start()(Code)
Returns the start index of the previous match.

The index of the first character matched
throws:
  IllegalStateException - If no match has yet been attempted,or if the previous match operation failed



start
public int start(int group)(Code)
Returns the start index of the subsequence captured by the given group during the previous match operation.

Capturing groups 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().


Parameters:
  group - The index of a capturing group in this matcher's pattern The index of the first character captured by the group,or -1 if the match was successful but the groupitself did not match anything
throws:
  IllegalStateException - If no match has yet been attempted,or if the previous match operation failed
throws:
  IndexOutOfBoundsException - If there is no capturing group in the patternwith the given index



toMatchResult
public MatchResult toMatchResult()(Code)
Returns the match state of this matcher as a MatchResult . The result is unaffected by subsequent operations performed upon this matcher. a MatchResult with the state of this matcher
since:
   1.5



toString
public String toString()(Code)

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. The string representation of this matcher
since:
   1.5




useAnchoringBounds
public Matcher useAnchoringBounds(boolean b)(Code)
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. this matcher
See Also:   java.util.regex.Matcher.hasAnchoringBounds
since:
   1.5




usePattern
public Matcher usePattern(Pattern newPattern)(Code)
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.


Parameters:
  newPattern - The new pattern used by this matcher This matcher
throws:
  IllegalArgumentException - If newPattern is null
since:
   1.5



useTransparentBounds
public Matcher useTransparentBounds(boolean b)(Code)
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 transparentregions this matcher
See Also:   java.util.regex.Matcher.hasTransparentBounds
since:
   1.5




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.