$A = -4; $w = 500; then $re = '/^\s*(\Q$A\E\s*\*?\s*\Qcos\E\s+\Q$w\E\s*\Qt\E\s+\QA\E||\Q$A\E\s*\*?\s*\Qcos\E\s*\(\s*\Q$w\E\s*\Qt\E\s*\)\s+\QA\E)\s*$/'; will accept answers in the following form: -4cos 500t A -4 cos 500t A -4*cos 500t A -4*cos(500t) A -- and any number of spaces before and after *, t, ( and )