I need to separate a large list of letters and names, I need to separate commas, but some names have commas in them, so I have to deal with this in the first place. Fortunately, the names are between the quotation marks.
At the moment, I get with the release of my regular expression, for example, (editing: it does not display messages on the forum that I see!):
"Talboom, Esther" "Wolde, Jos van der" "Debbie Derksen" < deberken@casema.nl >, corine < corine5@xs4all.nl >, "
The latter went wrong because the name does not have a comma, so it continues until it finds one, and this is the one I want to use for separation. So I want it to look until it finds a "<". How can i do this?
import java.util.regex.Pattern; import java.util.regex.Matcher; String test = "\"Talboom, Esther\" < E.Talboom@wegener.nl >, \"Wolde, Jos van der\" < J.vdWolde@wegener.nl >, \"Debbie Derksen\" < deberken@casema.nl >, corine < corine5@xs4all.nl >, \"Markies Aart\" < A.Markies@wegenernieuwsmedia.nl >"; Pattern pattern = Pattern.compile("\".*?,.*?\""); Matcher matcher = pattern.matcher(test); boolean found = false; while (matcher.find ()) { System.out.println(matcher.group()); }
edit: the best line to work as not everyone has a name or quotation marks:
String test = "\"Talboom, Esther\" < E.Talboom@wegener.nl >, DRP - Wouter Haan < wouter@drp.eu >, \"Wolde, Jos van der\" < J.vdWolde@wegener.nl >, \"Debbie Derksen\" < deberken@casema.nl >, corine < corine5@xs4all.nl >, clankilllller@gmail.com , \"Markies Aart\" < A.Markies@wegenernieuwsmedia.nl >";