Input String : "slack,users@xyz.com , slack,auditors@xyz.com , abc@xyz.com"
Regex I am using :
(.+?)@(.+?),
Current Output :
Group 0 - slack,users@xyz.com ,
Group 1 - slack,auditors@xyz.com ,
The output I want :
Group 0 - slack,users@xyz.com
Group 1 - slack,auditors@xyz.com
Group 2 - abc@xyz.com
My Code :
String regex = "(.+?)@(.+?),";
Pattern pattern = Pattern.compile(regex);
Matcher m =pattern.matcher("slack,users@xyz.com , slack,auditors@xyz.com , abc@xyz.com");
while(m.find()){
System.out.println(m.group());
}
How do I modify my regex so that it will make the ending comma optional so that the last group in the form of "user@domain" is also matched?
Also, how can i split the string in some way so that the ending comma is not part of the resulting groups?