Evaluate polynomial expression string Create a function which takes a polynomial equation, a value for x and returns the result of the operation.

Example: given 4x^2+2x-5 and x=3 output 37. This is the result of 4(3)^2+2(3)-5


Assume all polynomials are valid 
Polynomial format will always be coefficient(variable)^exponent =&gt; 4x^2 except :


When exponent is 1 it will be coefficient(variable) =&gt; 4x
When coefficient is 1 it will be (variable)^exponent =&gt; x^2

Polynomials are one variable only
Use of external libraries are forbidden
The coefficient and variable input can be positive and negative numbers.


Test cases


("3x^3-5x^2+2x-10", 5)          =&gt; 250
("10x^4-5x^3-10x^2+3x+50", 3)   =&gt; 644
("10x+20", 10)                  =&gt; 120
("-20x^2+20x-50", -8)           =&gt; -1490
("9", 5)                        =&gt; 9
("8x^2+5", 0)                   =&gt; 5




Update


Polynomial format will always be coefficient(variable)^exponent =&gt; 4x^2 except :


When exponent is 1 it will be coefficient(variable) =&gt; 4x
When coefficient is 1 it will be (variable)^exponent =&gt; x^2

Removed the rule of negative exponent. My mistake. A valid polynomial does not contain negative exponent
An exponent of 0 would be just coefficient
Added test case for input 0




This is code-golf, so the shortest answer in bytes win.
JavaScript (ES7), 48 bytes

Based upon a suggestion from @RickHitchcock

Expects X in uppercase. Takes input in currying syntax (p)(X).



p=&gt;X=&gt;eval(p.replace(/[X^]/g,c=&gt;c&lt;{}?'*X':'**'))


Try it online!



JavaScript (ES7), 49 bytes

Same approach as @DeadPossum. Takes input in currying syntax (p)(x).

p=&gt;x=&gt;eval(p.split`x`.join`*x`.split`^`.join`**`)


Try it online!