Reputation:
I want to split this string: 315-045/10-20 to this array: ["315","045","10","20"], meaning it should be split around every occurrence of '/' or '-'. Is it possible to do it with one call to the split() function?
Upvotes: 2
Views: 1190
Reputation: 159844
You could alternatively use a non-digit split
pattern:
"315-045/10-20".split("\\D");
Upvotes: 4
Reputation: 28697
You can use a regex which accepts both slashes and dashes.
String input = "315-045/10-20";
String[] output = input.split("[/-]");
Upvotes: 5