I think you just need to brutally strip all spaces from the import input string, it looks easier to me.
Then after explode with coma, the generated classes will automatically be OK.
NOTE: The external class individual input already converts spaces to dashes.
It is only the list import which doesn’t handle spaces.