// 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 UrlParse {
   private static Pattern p = Pattern.compile("(http|ftp|https)://[a-z0-9\\-]+(\\.[a-z0-9\\-]+)+(/[A-Za-z0-9_\\-\\.]*)*");
   public static void main(String[] args) throws Exception {
      String s = "abc http://www.xxx.dk def https://www.xxx.dk ghi ftp://ftp.xxx.dk jkl http://www.xxx.dk/ 123  http://www.xxx.dk/dir/ 456  http://www.xxx.dk/dir/fil.html 789  http://www.xxx.dk/dir/subdir/fil.html slut";
      Matcher m = p.matcher(s);
      while (m.find()) {
         System.out.println(m.group(0));
      }
   }
}
