Java regex stop after first occurrence
807603Feb 26 2008 — edited Feb 26 2008When using code like the following:
while (matcher.find()) {
string1=matcher.group(1).trim();
System.out.println(charset);
}
the program goes on looking all through the input string and prints out the final match.
What should be done to find the first occurrence and to stop searching through the input string after the first match has been found? i.e. I want to exit the while loop after the first match is found.