on 04-27-2007 12:38 PM
public static void main(String args[]){
String strContent="The original message was received at Mon, 9 Apr 2007 16:08:36 +0800" +
"----- The following addresses had permanent johnson@mail.vu fatal errors -----" +
"<robinsonamerereee@hotmail.com>" +
" ----- Transcript of session follows -----" +
"... while talking to 123123@mail.com keiru@mail.com mx1.hotmail.com" +
">>> RCPT To:<robinsonamerereee@hotmail.com>" +
"<<< 550 Requested action not taken: mailbox keiru@mail.com unavailable" +
"Sender: [kent@yahoo.com]";
parseMailAddress(strContent);
}
public static String[] parseMailAddress(String newStrContent){
String[] strArrMail=new String[]{};
String str="";
String regex = "(\w+)@(\w+\.)(\w+)(\.\w+)*";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(newStrContent);
while (matcher.find()) {
String found = matcher.group();
System.out.println("Found a match: " + found);
str = str.replaceAll(found+",","");
str=str +found+",";
}
System.out.println("MATCHER RESULT :" +str);
strArrMail=str.split(",");
return strArrMail;
}
Result:
johnson@mail.vu,123123@mail.com,robinsonamerereee@hotmail.com,keiru@mail.com,KENT@yahoo.com
if i want to eliminate the email with [KENT@yahoo.com] from the result which is in brackets ...how do i do this..
How about doing it in two steps?
First find addresses of the form \[\w@\w(\.\w)\]
and then use Matcher.replace() to replace these with empty strings.
Then use your original method to filter out the rest.
Regards,
Jens
P.S.: There are mail addresses of the form (\w\.)\w@\w(\.\w) (i.e. ones with one or more dots <b>before</b> the @-sign; don't you want to filter these, too?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
you can remove a specific part in a string using this.
First find the position of the string to be removed, using the IndexOf() function in Strings.
public static String removeCharAt(String s, int pos) {
return s.substring(0,pos)s.substring(pos1);
}
regards
Vivek Nidhi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
public static String[] parseMailAddress(String newStrContent){
String[] strArrMail=new String[]{};
String str="";
//String regex = "(\w+)@(\w+\.)(\w+)(\.\w+)*";
String regex = "[a-b].*\[*.*\][a-b].*"; //replace with your pattern
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(newStrContent);
while (matcher.find()) {
String found = matcher.group();
System.out.println("Found a match: " + found);
str = str.replaceAll(found+",","");
str=str +found+",";
}
System.out.println("MATCHER RESULT :" +str);
strArrMail=str.split(",");
return strArrMail;
}
i cannot filter anything...
what i want is simple extract the string that have email address but excludes the email address when it meet the brackets[john@yahoo.com]
adfafsd@yahoo.com , afadfafd@yahoo.com , simadfa@yahoo.com [sfdsass@yahoo.com]
the final selection should be :
adfafsd@yahoo.com , afadfafd@yahoo.com , simadfa@yahoo.com
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.