import java.util.regex.*;
public class Splitter {
public static void main(String[] args) throws Exception {
Pattern p = Pattern.compile("[,\\s]+");
String[] results = p.split("one,two, three four , five");
for (String result : results) {
System.out.println(result);
}
}
}
The splitter is either a comma or a whitespace or a combination of any number of them. I thought the regular expression for it should be [,\s]+
. Why was there an extra backslash in the example?