Reputation: 91
I'm in doubt on how to do an regex, to break an string in all white-spaces, hyphen and semicolon, it's in Java. I'm doing:String[] tmp = input.nextLine().split("\\s:-");
but it's not working, which is the right way ?
Upvotes: 0
Views: 2556
Reputation: 4794
You're currently splitting on all three of them in a row. Try character classes, which picks out any one from the selection:
String[] tmp = input.nextLine().split("[\\s:\\-]");
(hyphens have meaning in character classes, so you should escape them, too.)
Upvotes: 2