package jsoup;
import java.io.IOException;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class CatchEmail {
public static void main(String[] args) throws IOException {
String html = "<a href=\"mailto:[email protected]\">Gary Lim Hock Seng </a><a href=\"mailto:[email protected]\">Gary Lim Hock Seng<a href=\"mailto:張許郵箱\"> </a>";
// String html="dddd";
Document doc = Jsoup.parse(html);
// Document doc=Jsoup.connect("http://www.sqlife.cn").get();
Elements links = doc.select("a[href^=mailto]");
//找出所有郵箱
for (Element lnk : links) {
String email = lnk.attr("href").substring(7);
System.out.println(email);
// System.out.printf("%s:%s\n", lnk.text(), email);
}
//判斷郵箱格式
Pattern pattern = Pattern
.compile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
Matcher matcher = pattern.matcher("[email protected]");
System.out.println(matcher.matches());
}
}