equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
26 package java.util.regex; |
26 package java.util.regex; |
27 |
27 |
28 import java.util.Objects; |
28 import java.util.Objects; |
29 |
29 |
30 /** |
30 /** |
31 * An engine that performs match operations on a {@link java.lang.CharSequence |
31 * An engine that performs match operations on a {@linkplain java.lang.CharSequence |
32 * </code>character sequence<code>} by interpreting a {@link Pattern}. |
32 * character sequence} by interpreting a {@link Pattern}. |
33 * |
33 * |
34 * <p> A matcher is created from a pattern by invoking the pattern's {@link |
34 * <p> A matcher is created from a pattern by invoking the pattern's {@link |
35 * Pattern#matcher matcher} method. Once created, a matcher can be used to |
35 * Pattern#matcher matcher} method. Once created, a matcher can be used to |
36 * perform three different kinds of match operations: |
36 * perform three different kinds of match operations: |
37 * |
37 * |
328 text = input; |
328 text = input; |
329 return reset(); |
329 return reset(); |
330 } |
330 } |
331 |
331 |
332 /** |
332 /** |
333 * Returns the start index of the previous match. </p> |
333 * Returns the start index of the previous match. |
334 * |
334 * |
335 * @return The index of the first character matched |
335 * @return The index of the first character matched |
336 * |
336 * |
337 * @throws IllegalStateException |
337 * @throws IllegalStateException |
338 * If no match has yet been attempted, |
338 * If no match has yet been attempted, |
400 public int start(String name) { |
400 public int start(String name) { |
401 return groups[getMatchedGroupIndex(name) * 2]; |
401 return groups[getMatchedGroupIndex(name) * 2]; |
402 } |
402 } |
403 |
403 |
404 /** |
404 /** |
405 * Returns the offset after the last character matched. </p> |
405 * Returns the offset after the last character matched. |
406 * |
406 * |
407 * @return The offset after the last character matched |
407 * @return The offset after the last character matched |
408 * |
408 * |
409 * @throws IllegalStateException |
409 * @throws IllegalStateException |
410 * If no match has yet been attempted, |
410 * If no match has yet been attempted, |
645 * <p> If the match succeeds then more information can be obtained via the |
645 * <p> If the match succeeds then more information can be obtained via the |
646 * <tt>start</tt>, <tt>end</tt>, and <tt>group</tt> methods, and subsequent |
646 * <tt>start</tt>, <tt>end</tt>, and <tt>group</tt> methods, and subsequent |
647 * invocations of the {@link #find()} method will start at the first |
647 * invocations of the {@link #find()} method will start at the first |
648 * character not matched by this match. </p> |
648 * character not matched by this match. </p> |
649 * |
649 * |
|
650 * @param start the index to start searching for a match |
650 * @throws IndexOutOfBoundsException |
651 * @throws IndexOutOfBoundsException |
651 * If start is less than zero or if start is greater than the |
652 * If start is less than zero or if start is greater than the |
652 * length of the input sequence. |
653 * length of the input sequence. |
653 * |
654 * |
654 * @return <tt>true</tt> if, and only if, a subsequence of the input |
655 * @return <tt>true</tt> if, and only if, a subsequence of the input |
734 * |
735 * |
735 * <p> The replacement string may contain references to subsequences |
736 * <p> The replacement string may contain references to subsequences |
736 * captured during the previous match: Each occurrence of |
737 * captured during the previous match: Each occurrence of |
737 * <tt>${</tt><i>name</i><tt>}</tt> or <tt>$</tt><i>g</i> |
738 * <tt>${</tt><i>name</i><tt>}</tt> or <tt>$</tt><i>g</i> |
738 * will be replaced by the result of evaluating the corresponding |
739 * will be replaced by the result of evaluating the corresponding |
739 * {@link #group(String) group(name)} or {@link #group(int) group(g)</tt>} |
740 * {@link #group(String) group(name)} or {@link #group(int) group(g)} |
740 * respectively. For <tt>$</tt><i>g</i><tt></tt>, |
741 * respectively. For <tt>$</tt><i>g</i>, |
741 * the first number after the <tt>$</tt> is always treated as part of |
742 * the first number after the <tt>$</tt> is always treated as part of |
742 * the group reference. Subsequent numbers are incorporated into g if |
743 * the group reference. Subsequent numbers are incorporated into g if |
743 * they would form a legal group reference. Only the numerals '0' |
744 * they would form a legal group reference. Only the numerals '0' |
744 * through '9' are considered as potential components of the group |
745 * through '9' are considered as potential components of the group |
745 * reference. If the second group matched the string <tt>"foo"</tt>, for |
746 * reference. If the second group matched the string <tt>"foo"</tt>, for |