I am using the following code (simplified) to extract the title of an html page:
REGEX = "<TITLE>(.*?)</TITLE>";
pattern = Pattern.compile(REGEX,Pattern.CASE_INSENSITIVE);
matcher = pattern.matcher(contents);
//contents is the string which holds the file

if (matcher.find()) {




The problem is that if a page contains more than one <title></title> pair this code continues after the first match and returns the final match. I want it to stop after the first match. In php the matches are stored in an array and I can extract them by accessing the array. How can it be done in Java?