• Post Reply Bookmark Topic Watch Topic
  • New Topic

java string[] splitting for email id  RSS feed

 
Mobio Dev
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to JavaRanch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!