Edit: -
If you want xw be together in the resulting array, you need to split the line: -
String[] arr = str.split("[-+\\d]+");
Result: -
[, x, y, x, w, x, w, z, x, w, y, xw, x, x, x, w, z]
You can replace all unnecessary characters with an empty string and split into an empty string.
String str = "3x2y3+5x2w3-8x2w3z4+3-2x2w3+9y-4xw-x2x3+8x2w3z4-4"; str = str.replaceAll("[-+\\d]", ""); String[] arr = str.split(""); System.out.println(Arrays.toString(arr));
Note that this will add an empty string as the first element of your array that you can handle.
Result: -
[, x, y, x, w, x, w, z, x, w, y, x, w, x, x, x, w, z]
Please note that the - sign in your question is different. You must replace it with a keyboard. It currently does not match the - sign.