I imagine that error would be obtained if you passed
select * from table where fieldname regexp '.\(.';
instead of
select * from table where fieldname regexp '.\\(.';
Are you sure you built your string correctly? I suspect you actually built the former strings.
For example, the code
"select * from table where fieldname regexp '.\\(.';"
produces the undesirable string
select * from table where fieldname regexp '.\(.';
while the code
"select * from table where fieldname regexp '.\\\\(.';"
produces the desired string
select * from table where fieldname regexp '.\\(.';