Java Reference
In-Depth Information
sb.append(" and ending at ");
sb.append(matchEnd);
System.out.println(sb);
}
}
}
matcher.group gives us the text being matched (that's essentially the result of the pattern we specify
in the second argument). matcher.start gives us the starting position of the matched string within the
input string (the first argument). matcher.end gives us the ending position of the matched string. I used a
StringBuilder object to avoid a really long line, which is awkward to read in a book. I often use
StringBuilder objects within my production code, too, for the sake of performance (the concatenation
operator is the worst way to create a String object).
Before we plunge into the syntax of regular expressions, let's cover how to pass values to the
RegexTester program. In doing so, we'll also run it for the first time. To set up arguments for
RegexTester, follow these steps.
1.
From the Run menu, choose Run Configurations. The Run Configurations
window appears, as shown in Figure 15-2.
Figure 15-2. Run configurations for RegexTester
Search WWH ::




Custom Search