Hey there! Sign in to join this conversationNew here? Join for free
x Turn on thread page Beta

regex for math expressions watch

    • Thread Starter

    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.
Submit reply
Turn on thread page Beta
Updated: October 17, 2015
Do you like carrot cake?

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.