Painless code in watcher for replacing doble quotes

Hello,

 I have a problem using painless code in a watcher. I need to replace all the double quotes characters and put a single quote instead, but I don't know how I can do this. After read the Elastic documentation I put the following in the code:
"transform": {
    "script": {
      "source": """
            return ctx.payload.hits.hits.stream()
           .map(hit -> {
             def last = hit.inner_hits.test_cases.hits.hits[0];
             def errorMessage = last.fields['error.message']?.0;
             errorMessage = /[\"]/.matcher(errorMessage).replaceAll('\'');

But I obtain this error:

"transform": {
"type": "script",
"status": "failure",
"reason": "runtime error",
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"errorMessage = /[\"]/.matcher(errorMessage).replaceAll('\'');\n \n\n ",
" ^---- HERE"
],
"script": " ...",
"lang": "painless",
"position": {
"offset": 987,
"start": 957,
"end": 1047
}
}
],
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"errorMessage = /[\"]/.matcher(errorMessage).replaceAll('\'');\n \n\n ",
" ^---- HERE"
],
"script": " ...",
"lang": "painless",
"position": {
"offset": 987,
"start": 957,
"end": 1047
},
"caused_by": {
"type": "null_pointer_exception",
"reason": "Cannot invoke "java.lang.CharSequence.length()" because "this.wrapped" is null"
}
}
},
"actions":
},
"messages": [
"failed to execute watch transform"
]
}

Can someone help me to solve this problem? I only need to find all " characters and replace them using ' characters using painless code inside a watcher (the errorMessage field is a normal String field).

Many thanks!