// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.regex.*;

public class H1Parse {
   private static Pattern p = Pattern.compile("(?:<h1>)(.*?)(?:</h1>)", Pattern.DOTALL);

   public static void findHeaders(String s) {
      Matcher m = p.matcher(s);
      while (m.find()) {
         System.out.println("h1=" + m.group(1));
      }
   }

   public static void main(String[] args) throws Exception {
      findHeaders("<h1>xxx</h1>\r\nyyy");
      findHeaders("<h1>xxx</h1>\r\nyyy\r\n<h1>zzz</h1>\r\nwww");
      findHeaders("<h1>xxx</h1>\r\nyyy\r\n<h1>zzz\r\nzzz</h1>\r\nwww");
   }
}
