java邮件识别(可通用)

import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class reconized {

/**
* @param args
*/
//需要切分的字符串
private static String str = "123abc邮件:[email protected]";
private static String s = "[email protected]";
private static String result;
public static void main(String[] args) {
// TODO Auto-generated method stub
result = qie(str);
if(reco(result)){
System.out.println("这是一个符合邮件格式的字符串");
System.out.println(result);
}
}
//字符串切分方法
private static String qie(String s){
int i = s.indexOf(":");
int ii = s.indexOf("com");
String ss = s.substring(i+1, ii);
return ss+"com";
}
//切分字符串格式判断方法
private static boolean reco(String s){
Pattern p = Pattern.compile("^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\\.([a-zA-Z0-9_-])+)+$");
Matcher matcher = p.matcher(s);
return matcher.matches();
}
}

你可能感兴趣的:(java)