Pattern matching with parentheses

I need my students to be able to specifically enter parentheses in their equation and then validate that they entered it correctly.

I want to take it step by step
so I give them d^3 + (c^2 - 2) when d is 2/5 and c is -4

I want them to respond by typing in \left(\frac{2}{5}\right)^{3}\ +\ \left(\left(-4\right)^{2}\ -\ 2\right)
(2/5)^3 + ((-4)^2 - 2)

and check their pattern to see if it is correct. I have tried variations of the following:
pattern = p.sum(p.exponent(p.integer.allowParens,p.integer),p.difference(p.exponent(p.integer.allowParens,p.integer),p.integer).allowParens).allowParens
pattern.matches(this.latex)

AND
pattern = p.sum(p.exponent(p.integer,p.integer),p.difference(p.exponent(p.integer,p.integer),p.integer))
matches = pattern.allowNegativeTerms.allowParens.matches(this.latex)

AND other iterations, but none seem to be working

Since you’re asking students to substitute “d” with 2/5, your pattern is going to come up false because it’s looking for an integer pattern instead of a fraction pattern.

I didn’t think of that. You are right. I will fix that and see if it helps. I just needed a second pair of eyes. Thanks. I’ll post again if it doesn’t work.