-1

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.

rafaelc
  • 57,686
  • 15
  • 58
  • 82
Jayaram
  • 6,276
  • 12
  • 42
  • 78

1 Answers1

1

If you just want the constants you can simply use a negative look-behind :

>>> re.findall(r'(?<!\*\*)\d',s)
['3', '5', '6']

r'(?<!\*\*)\d' will match any number that not preceding with double * character.

Mazdak
  • 105,000
  • 18
  • 159
  • 188