2016-08-17 22 views

回答

0

模式的识别URL(基于关闭RFC 3986)

private static final Pattern urlPattern = Pattern.compile(
     "(?:^|[\\W])((ht|f)tp(s?):\\/\\/|www\\.)" 
       + "(([\\w\\-]+\\.){1,}?([\\w\\-.~]+\\/?)*" 
       + "[\\p{Alnum}.,%_=?&#\\-+()\\[\\]\\*[email protected]!:/{};']*)", 
     Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL); 


//Usage: email content goes as input here.. 
Matcher matcher = urlPattern.matcher("foo bar http://example.com baz"); 

while (matcher.find()) { 
    int matchOffsetStart = matcher.start(1); 
    int matchOffsetEnd = matcher.end(); 
    // now you have the offsets of a URL match 
} 

UPDATE: 如果你想读像等消息头,我会建议使用Mime4J

Message msg = new Message(new FileInputStream("mime.msg")); 

msg.getFrom()会给你从。同样,你可以提取任何你想要的。

Refer for more details here

+0

谢谢Sunil的模式,在此之前,我需要先等待并验证电子邮件,而不是解析该电子邮件的内容。 – Aminul

+0

验证电子邮件 - 你的意思是发送人的权利?我没有完全得到你 –

+0

我的步骤应该是 - 1.需要检查预期的电子邮件是否已发送,2.然后我将解析网址并继续。 – Aminul

相关问题