I am trying to find the format \"abc, def g\" which is a name format \"lastname, firstname middlename\". I think the best suited method is regex but I do not have any idea i
As an alternative to matching the lastname, firstname middlename
directly, you could use String.split and provide a regexp that matches the separators, instead. For instance:
static String[] lastFirstMiddle(String input){
String[] result=input.split("[,\\s]+");
System.out.println(Arrays.asList(result));
return result;
}
I tested this with inputs
"Müller, firstname middlename"
"Müller,firstname middlename"
"O'Gara, Ronan Ramón"
Note: this approach fails with surnames that contain spaces, for instance "van der Heuvel", "de Valera", "mac Piarais" or "bin Laden" but then again, OP's original specification does not seem to admit of spaces in the surname (or the other names. I work with a "Mary Kate". That's her first name, not first and middle). There's an interesting page about personal names at http://www.w3.org/International/questions/qa-personal-names