Pulling all numbers from a quadratic equation using RE

I have the below quadratic equation from which i’m looking to pull the constants into a tuple to find the factors.

3*(x**2)+5*x+6 – (I also don’t want to pull the power 2).

I tried the below expressions. Most of them seem to be returning None

re.search('(d*),(d*),(d*)','3*(x**2)+5*x+6').groups() - returns None

re.findall('([0-9]+.*)+([0-9]+.*)+([0-9]+.*)','3*(x**2)+5*x+6') - returns None

re.split('D','3*(x**2)+5*x+6') - this is the closest i got - returns - ['3', '', '', '', '', '2', '', '5', '', '', '6']

Any ideas? I would prefer to use re as opposed to any other module.


Source: regex

Leave a Reply