My program works how I want it to but I stumbled upon something that I don't understand.
String problem = "4 - 2";
problem = problem.replaceAll("[^-?+?0-9]+", " ");
System.out.println(Arrays.asList(problem.trim().split(" ")));
prints [4, -, 2]
but
String problem = "4 - 2";
problem = problem.replaceAll("[^+?-?0-9]+", " ");
System.out.println(Arrays.asList(problem.trim().split(" ")));
doesn't even do anything with the minus sign and prints [4, 2]
Why does it do that, it seems like both should work.