-1

我正在开发一个邮件检索器,用于仅检索一些需要的邮件,并使用正则表达式进一步从这些邮件中提取详细信息。我必须从以下邮件中提取名称、要求等详细信息。如何用正则表达式做到这一点?请帮我解决一下这个。提前致谢。

Lead Details 
Caller Name: Mr Rahul from Rajouri Garden 
Caller Requirement: Money Exchangers 
Caller Phone: +918459761134 
Caller Email: rchand.rahul@gmail.com 
Call Date & Time: Tue, 18 Jun 2013 14:40:38 
Branch Info: Rajouri Garden 
City: Delhi 
4

1 回答 1

0

试试这个,你可以从文件中获取输入。

public class Test {
public static void main(String[] args) {
    String data = " Lead Details\n" +
            "Caller Name: Mr Rahul from Rajouri Garden\n" +
            "Caller Requirement: Money Exchangers\n" +
            "Caller Phone: +918459761134\n" +
            "Caller Email: rchand.rahul@gmail.com\n" +
            "Call Date & Time: Tue, 18 Jun 2013 14:40:38\n" +
            "Branch Info: Rajouri Garden\n" +
            "City: Delhi";

    String[] subStr=data.split("\n");

    for (String i:subStr){
        if(i.contains("Caller Name")){
            System.out.println("Caller Name: "+i.split(":")[1]);
        }if(i.contains("Caller Requirement")){
            System.out.println("Caller Requirement: "+i.split(":")[1]);
        }if(i.contains("Caller Phone")){
            System.out.println("Caller Phone: "+i.split(":")[1]);
        }if(i.contains("Caller Email")){
            System.out.println("Caller Email: "+i.split(":")[1]);
        }if(i.contains("Call Date & Time")){
            System.out.println("Call Date & Time: "+i.split(":")[1]);
        }if(i.contains("Branch Info")){
            System.out.println("Branch Info: "+i.split(":")[1]);
        }if(i.contains("City")){
            System.out.println("City: "+i.split(":")[1]);
        }
    }
}

}
于 2013-07-11T17:04:14.763 回答