正则表达式提取内容
字符串类似内容:Date:Mon,27Apr201523:45:50-0700(PDT)From:"feedback@service.alibaba.com"<feedb...
字符串类似内容:
Date:Mon, 27 Apr 2015 23:45:50 -0700 (PDT)
From:"feedback@service.alibaba.com" <feedback@service.alibaba.com>
Reply-To:Julia Tratosphera <tratosphera@gmail.com>
To:sales06@brifar.com, brifar@brifar.com, kevinwang@brifar.cn
需要提取Julia Tratosphera 和tratosphera@gmail.com
java怎么写法 啊?
Reply-To: 里面的 展开
Date:Mon, 27 Apr 2015 23:45:50 -0700 (PDT)
From:"feedback@service.alibaba.com" <feedback@service.alibaba.com>
Reply-To:Julia Tratosphera <tratosphera@gmail.com>
To:sales06@brifar.com, brifar@brifar.com, kevinwang@brifar.cn
需要提取Julia Tratosphera 和tratosphera@gmail.com
java怎么写法 啊?
Reply-To: 里面的 展开
1个回答
展开全部
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static void main(String[] args) throws Exception {
String str = "Date:Mon, 27 Apr 2015 23:45:50 -0700 (PDT)\r\n"
+ "From:\"feedback@service.alibaba.com\" <feedback@service.alibaba.com>\r\n"
+ "Reply-To:Julia Tratosphera <tratosphera@gmail.com>\r\n"
+ "To:sales06@brifar.com, brifar@brifar.com, kevinwang@brifar.cn";
String regex = "Reply-To:([^<]*)<([^>]*)";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
if (matcher.find()) {
String name = matcher.group(1).trim();
String email = matcher.group(2).trim();
System.out.println(name);
System.out.println(email);
}
}
}
正则为:Reply-To:([^<]*)<([^>]*);组1是姓名,组2是邮箱。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询