src/share/classes/java/util/regex/Matcher.java

Print this page




 813      *
 814      * <ol>
 815      *
 816      *   <li><p> It reads characters from the input sequence, starting at the
 817      *   append position, and appends them to the given string builder.  It
 818      *   stops after reading the last character preceding the previous match,
 819      *   that is, the character at index {@link
 820      *   #start()}&nbsp;<tt>-</tt>&nbsp;<tt>1</tt>.  </p></li>
 821      *
 822      *   <li><p> It appends the given replacement string to the string builder.
 823      *   </p></li>
 824      *
 825      *   <li><p> It sets the append position of this matcher to the index of
 826      *   the last character matched, plus one, that is, to {@link #end()}.
 827      *   </p></li>
 828      *
 829      * </ol>
 830      *
 831      * <p> The replacement string may contain references to subsequences
 832      * captured during the previous match: Each occurrence of
 833      * <tt>$</tt><i>g</i><tt></tt> will be replaced by the result of
 834      * evaluating {@link #group(int) group}<tt>(</tt><i>g</i><tt>)</tt>.
 835      * The first number after the <tt>$</tt> is always treated as part of
 836      * the group reference. Subsequent numbers are incorporated into g if
 837      * they would form a legal group reference. Only the numerals '0'
 838      * through '9' are considered as potential components of the group
 839      * reference. If the second group matched the string <tt>"foo"</tt>, for
 840      * example, then passing the replacement string <tt>"$2bar"</tt> would
 841      * cause <tt>"foobar"</tt> to be appended to the string builder. A dollar
 842      * sign (<tt>$</tt>) may be included as a literal in the replacement
 843      * string by preceding it with a backslash (<tt>\$</tt>).
 844      *
 845      * <p> Note that backslashes (<tt>\</tt>) and dollar signs (<tt>$</tt>) in
 846      * the replacement string may cause the results to be different than if it
 847      * were being treated as a literal replacement string. Dollar signs may be
 848      * treated as references to captured subsequences as described above, and
 849      * backslashes are used to escape literal characters in the replacement
 850      * string.
 851      *
 852      * <p> This method is intended to be used in a loop together with the
 853      * {@link #appendTail appendTail} and {@link #find find} methods.  The




 813      *
 814      * <ol>
 815      *
 816      *   <li><p> It reads characters from the input sequence, starting at the
 817      *   append position, and appends them to the given string builder.  It
 818      *   stops after reading the last character preceding the previous match,
 819      *   that is, the character at index {@link
 820      *   #start()}&nbsp;<tt>-</tt>&nbsp;<tt>1</tt>.  </p></li>
 821      *
 822      *   <li><p> It appends the given replacement string to the string builder.
 823      *   </p></li>
 824      *
 825      *   <li><p> It sets the append position of this matcher to the index of
 826      *   the last character matched, plus one, that is, to {@link #end()}.
 827      *   </p></li>
 828      *
 829      * </ol>
 830      *
 831      * <p> The replacement string may contain references to subsequences
 832      * captured during the previous match: Each occurrence of
 833      * <tt>$</tt><i>g</i> will be replaced by the result of
 834      * evaluating {@link #group(int) group}<tt>(</tt><i>g</i><tt>)</tt>.
 835      * The first number after the <tt>$</tt> is always treated as part of
 836      * the group reference. Subsequent numbers are incorporated into g if
 837      * they would form a legal group reference. Only the numerals '0'
 838      * through '9' are considered as potential components of the group
 839      * reference. If the second group matched the string <tt>"foo"</tt>, for
 840      * example, then passing the replacement string <tt>"$2bar"</tt> would
 841      * cause <tt>"foobar"</tt> to be appended to the string builder. A dollar
 842      * sign (<tt>$</tt>) may be included as a literal in the replacement
 843      * string by preceding it with a backslash (<tt>\$</tt>).
 844      *
 845      * <p> Note that backslashes (<tt>\</tt>) and dollar signs (<tt>$</tt>) in
 846      * the replacement string may cause the results to be different than if it
 847      * were being treated as a literal replacement string. Dollar signs may be
 848      * treated as references to captured subsequences as described above, and
 849      * backslashes are used to escape literal characters in the replacement
 850      * string.
 851      *
 852      * <p> This method is intended to be used in a loop together with the
 853      * {@link #appendTail appendTail} and {@link #find find} methods.  The