我有以下文字。
emailString = "Jhon, N, Edward, <edward@sri.lk>, " +
"Mickal, Lantz, <mickal@sri.lk>, " +
"Thomas, F, Kevin, <kevin@sri.lk>, " +
"Marina, Anderson, <marina@sri.lk>, " +
"Henry, Ford, <ford@sri.lk>, " +
"Davin, Cammeron, <Cammeron@sri.lk>";
从上面的文字中,我想一一列出每个信息,如下所示。
Jhon, N, Edward, <edward@sri.lk>
Mickal, Lantz, <mickal@sri.lk>
Thomas, F, Kevin, <kevin@sri.lk>
Marina, Anderson, <marina@sri.lk>
Henry, Ford, <ford@sri.lk>
Davin, Cammeron, <Cammeron@sri.lk>
我尝试使用 Java 正则表达式来做到这一点,但没有成功。
如何在 Java 中使用正则表达式解决这个问题?
以下是我使用的示例类。
public class MainFrame
{
private static final String emailString = "Jhon, N, Edward, <edward@sri.lk>, " +
"Mickal, Lantz, <mickal@sri.lk>, " +
"Thomas, F, Kevin, <kevin@sri.lk>, " +
"Marina, Anderson, <marina@sri.lk>, " +
"Henry, Ford, <ford@sri.lk>, " +
"Davin, Cammeron, <Cammeron@sri.lk>";
public MainFrame()
{
}
/**
* @param args
*/
public static void main(String[] args)
{
String regularExpression = "(([.])*([A-Za-z0-9])*([.*])*)*(<[a-z0-9-]+(\\.[a-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[a-z]{2,})>)([.])*([A-Za-z0-9])*([.*])*";
Pattern pattern = Pattern.compile(regularExpression);
Matcher matcher = pattern.matcher(emailString);
String[] emails = emailString.split(regularExpression);
for(String email : emails)
{
System.out.println("Email Address : " + email);
}
}
}