The regex parser fails to recognize in expressions such as
1/(4x-1), that 4x is 4 times x.
I tried to call
M("1/(4x - 1)") and I got the following transformation:
Integer (1 )/(Integer (4 )Symbol ('x' )-Integer (1 ))
Obviously, Integer(4) Symbol('x') is not valid, as an asterisk (*) is missing to represent the multiplication.
A quick makeshift fix:
your_mathematica_expr = '((-2x+5)(4x-1)-4(-x^2+5x+1))/(4x-1)^2'
new_math_expr = re.sub("([0-9])\ *([a-zA-Z])", "\\1 * \\2", your_mathematica_expr)
M(new_math_expr)