cancel
Showing results for 
Search instead for 
Did you mean: 

parseMailAddress

Former Member
0 Kudos

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..

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

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?

Former Member
0 Kudos

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

Former Member
0 Kudos

but the problem is i dont know the position of the string......

my requirement is simple

there is a reply mail.. ..... when i

see this bracket [] i want to excludes from my selection

Former Member
0 Kudos

Hi,

As what you have done before, you can find based on this reg expression and remove it or append with empty string.

String patternStr = "[a-b].*
[.
][a-b].*";

please let me know, how it goes.

regards

Vivek Nidhi.

Former Member
0 Kudos


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