import java.util.List;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.lang.System.out;
public class Control{
private static final String EMAIL_PATTERN =
"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
public static void main(String[] args) {
String delimiters = "\\s+|,";
String cadena= "From: thomasmuller@hotmail.com Subject: Prueba Time 04:12 pm";
//obtener el correo
imprime("original:"+cadena);
List<String> listaCadena = Arrays.asList(cadena.split(delimiters));
imprime(listaCadena.toString()+" tam: "+listaCadena.size());
String aux="";
for (int i=0; i< listaCadena.size() ; i++ ) {
Pattern p= Pattern.compile(EMAIL_PATTERN);
Matcher m= p.matcher(listaCadena.get(i));
if(m.find()){
aux+=listaCadena.get(i);
}
}
imprime(aux);
}
public static void imprime(String c){
out.println(c);
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.