How could you write a single regex which would match inputs for both linear and quadratic expressions correctly? For example, the expressions: (2x + 40 + 40), (x^2 + 3x + 2), (x^2 + 4), (x^2 + 2x). I want it to work so that I can group all the numbers, not the letters. E.g., I have a regex that will do the above but only for quadratics. If I input 1x^2 + 3x + 2 into this regex "([+-]?\\d+)[Xx]2\\s*([+-]?\\d+)[Xx]\\s*([+-]?\\d+)\\s*=\\s*0" it will return 1, 3, 2.
x Turn on thread page Beta
regex for math expressions watch
- Thread Starter
- 17-10-2015 16:17