public static Polynomial parse(String input) {
        Polynomial p = new Polynomial();
        input = input.replace(" ", "");
        input = input.replace("-", "+-");
        input = input.replace("–", "+-");
        String[] parts = input.split("\\+");
        for (String part : parts) {
            if (!(part.trim().equals(""))) {
                part+=" ";
                String[] subparts = part.split("x");

                String doubleString = subparts[0];
                if (doubleString.equals("") || doubleString.equals("-")) {
                    doubleString = doubleString + "1";
                }
                int power = 0;
                double coefficient = Double.parseDouble(doubleString);
                if (subparts.length > 1) {
                    String powerString = subparts[1];
                    powerString = powerString.trim();
                    if (powerString.contains("^")) {
                        power = Integer.parseInt(powerString.substring(1));
                        p.addTerm(power, coefficient);
                    } else {
                        power = 1;
                        p.addTerm(power, coefficient);
                    }
                } else {
                    p.addTerm(0, coefficient);
                }
            }
        }
        return p;
    }