I recently saw how to solve a problem of mine using java regex and the split method, so i wanted to learn regex I watched a few 20-30 min videos, and I thought I understood it, but in reality, those videos are only covering the basics I assume. Because there seems to be an order that expressions go, in order to split. for instance, this code splits the coefficients up but based off the knowledge from those videos this would actually split the x and the ^ char and ANY occurrence of a digit as well as any occurrence of a "+" But instead it splits the function so just the coefficients are left, Why?
code:
String polynomial = "-2x^2+3x^1+6"
String[] parts = polynomial.split("x\\^\\d+\\+?")
for (i = 0; i < part.length; i++){
System.out.println(parts[i])
}
I tried to write a split function that splits any num after the ^ char but before the + symbol of each "part" by doing \\d+\\x\\+
which just gave me an error.