Elements elements = doc.select("span.st");
for (Element e : elements) {
out.println("<p>Text : " + e.text()+"</p>");
}
元素e
包含带有一些电子邮件ID的文本。如何从中提取maild
id。我见过提供:matches(regex)
的Jsoup API文档,但我并不了解如何使用它。我试图使用
我在谷歌上搜索时发现的。^ [A-ZA-Z0-9 _#$%&安培;!?'* + / =`{|}〜^ .-] + @ [A-ZA-Z0-9 .-] + $
提前感谢您的帮助。
答案 0 :(得分:1)
:matches(regex)
非常有用。
我认为这不是你想要的。 Instead, you need to extract the email from e.text()
using regex。在你的情况下:
Elements elements = doc.select("span.st");
for (Element e : elements) {
out.println("<p>Text : " + e.text()+"</p>");
out.println(extractEmail(e.text()));
}
// ...
public static String extractEmail(String str) {
Matcher m = Pattern.compile("[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0- 9-.]+").matcher(str);
while (m.find()) {
return m.group();
}
return null;
}