2011-04-08 125 views

回答

5

由于听起来您正在处理标准格式的电子邮件地址(RFC 822),您可能需要考虑使用JavaMail API。你想要的代码很简单。例如,假设input包含您的电子邮件地址字符串:

String email = new InternetAddress(input).getAddress(); 
1

正则表达式是去(http://java.sun.com/developer/technicalArticles/releases/1.4regex/)

还是一个好办法你可以只用子工作...

沿东西线...

public static String getEmail(String x) { 
    int firstBracket = 0; 
    int secondBracket = 0; 

    firstBracket = x.indexOf("<"); 
    secondBracket = x.indexOf(">"); 
    return x.substring(firstBracket+1, secondBracket); 
} 

不一定是最可靠的解决方案......但它应该做的,如果表单的工作有保证。

0

请尝试使用正则表达式。像这样?

String name = "John Smith <[email protected]>"; 
String email = name.replaceFirst(".*<(.*?)>.*","$1");