|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 15 of 16
3 0: abc 1: abc 2: bc 3: c
Capturing group number 0 saves the previous match and has nothing to do with whether a capturing group appears in the pattern,
which is (.(.(.))). The other three capturing groups capture the characters of the previous match belonging to those capturing groups. For example,
number 2, (.(.)), captures bc; and number 3, (.), captures c.
Before we leave our discussion of Matcher's methods, we should examine four more match position methods:
public int start(): returns the previous match's start index. That method throws an IllegalStateException object if either the matcher has not yet attempted a match or the previous match operation failed.
public int start(int group): resembles the previous method, except it returns the previous match's start index associated with the capturing group that
group specifies. If no capturing group with the specified capturing group number exists in the pattern, start(int group) throws an IndexOutOfBoundsException object.
public int end(): returns the index of the last matched character plus 1 in the previous match. That method throws an IllegalStateException object if either the matcher has not yet attempted a match or the previous match operation failed.
public int end(int group): resembles the previous method, except it returns the previous match's end index associated with the capturing group that
group specifies. If no capturing group with the specified group number exists in the pattern, end(int group) throws an IndexOutOfBoundsException object.
The following example demonstrates two of the match position methods reporting start/end match positions for capturing group number 2:
Pattern p = Pattern.compile ("(.(.(.)))");
Matcher m = p.matcher ("abcabcabc");
while (m.find ())
{
System.out.println ("Found " + m.group (2));
System.out.println (" starting at index " + m.start (2) +
" and ending at index " + m.end (2));
System.out.println ();
}
The example produces the following output: