Is it better to use regex
or Stringtokenizer
to separate the author and title in this string:
William Faulkner - 'Light In August'
Is this the simplest regex
that would work?
Pattern pattern = Pattern.compile("^\\s*([^-]+)-.*$");
Matcher matcher = pattern.matcher("William Faulkner - 'Light In August'");
String author = matcher.group(1).trim();
String bookTitle = matcher.group(2).trim();
Is that overkill or is there a simpler way to do this with a Stringtokenizer
?
Basically I'm looking for the most transparent and maintainable solution since I don't have a good understanding of regex
and got help with the one above.