求一个正则:现有语句如下:
Contact:
陳
PeterShiu [email protected]已知:
group(1)的内容不知道,只知道group(1)里面没有Email格式的,group(2)是个email欲取出:group(1)=\n 陳\n PeterShiu
group(2)[email protected]我写了一个:感觉不好,能优化不
System.out.println("---------------------------------");
regEx = "Contact:((.|\\s)*)\\s+(([^\\s]+))\\s*";
String str4 = "Contact:\n 陳\n PeterShiu [email protected]\n";
m = Pattern.compile(regEx).matcher(str4);
if (m.matches())
{
for (int i = 0; i < m.groupCount(); i++)
{
System.out.printf("m.group(%d)=%s\n", i, m.group(i));
}
}
else
{
System.out.println("nothing");
}
限制条件:只使用正则,不要用其他方法
Contact:
陳
PeterShiu [email protected]已知:
group(1)的内容不知道,只知道group(1)里面没有Email格式的,group(2)是个email欲取出:group(1)=\n 陳\n PeterShiu
group(2)[email protected]我写了一个:感觉不好,能优化不
System.out.println("---------------------------------");
regEx = "Contact:((.|\\s)*)\\s+(([^\\s]+))\\s*";
String str4 = "Contact:\n 陳\n PeterShiu [email protected]\n";
m = Pattern.compile(regEx).matcher(str4);
if (m.matches())
{
for (int i = 0; i < m.groupCount(); i++)
{
System.out.printf("m.group(%d)=%s\n", i, m.group(i));
}
}
else
{
System.out.println("nothing");
}
限制条件:只使用正则,不要用其他方法
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货