| Author |
java string[] splitting for email id
|
Mobio Dev
Greenhorn
Joined: Nov 03, 2010
Posts: 6
|
|
hi experts, I'm having String temp = "Ms Abc<abc@gmail.com>;Mr Cde<cde@mail.com>;Miss Xyz<xyz@mail.com>";
now i have to split this temp string to ArrayList or String[] title, name, emailid so i'm able insert into db separate column for title, name and emailId, i'm able only split the email id using following code,
ArrayList emailIdList = new ArrayList();
Pattern p = Pattern.compile("\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b",Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(s);
while (m.find()){
emailIdList.add(m.group());
}
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16815
|
|
Mobio Dev wrote:
now i have to split this temp string to ArrayList or String[] title, name, emailid so i'm able insert into db separate column for title, name and emailId, i'm able only split the email id using following code,
Well, you pretty much got the hardest one done. Just put the email pattern in a group, and then add the groups for the title and name. Compare to the email, the other two groups should be easy.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
And welcome to JavaRanch
|
 |
 |
|
|
subject: java string[] splitting for email id
|
|
|