{"record":{"id":"ce94bae5889df722","repo":"prestodb/presto","slug":"invalid-function-argument-ce94ba","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"Illegal replacement sequence: ${replacement.toStringUtf8()}","messagePattern":"Illegal replacement sequence: (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/scalar/JoniRegexpFunctions.java","lineNumber":138,"sourceCode":"        return sliceOutput.slice();\n    }\n\n    private static void appendReplacement(SliceOutput result, Slice source, Regex pattern, Region region, Slice replacement)\n    {\n        // Handle the following items:\n        // 1. ${name};\n        // 2. $0, $1, $123 (group 123, if exists; or group 12, if exists; or group 1);\n        // 3. \\\\, \\$, \\t (literal 't').\n        // 4. Anything that doesn't starts with \\ or $ is considered regular bytes\n\n        int idx = 0;\n\n        while (idx < replacement.length()) {\n            byte nextByte = replacement.getByte(idx);\n            if (nextByte == '$') {\n                idx++;\n                if (idx == replacement.length()) { // not using checkArgument because `.toStringUtf8` is expensive\n                    throw new PrestoException(INVALID_FUNCTION_ARGUMENT, \"Illegal replacement sequence: \" + replacement.toStringUtf8());\n                }\n                nextByte = replacement.getByte(idx);\n                int backref;\n                if (nextByte == '{') { // case 1 in the above comment\n                    idx++;\n                    int startCursor = idx;\n                    while (idx < replacement.length()) {\n                        nextByte = replacement.getByte(idx);\n                        if (nextByte == '}') {\n                            break;\n                        }\n                        idx++;\n                    }\n                    byte[] groupName = replacement.getBytes(startCursor, idx - startCursor);\n                    try {\n                        backref = pattern.nameToBackrefNumber(groupName, 0, groupName.length, region);\n                    }\n                    catch (ValueException e) {","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/scalar/JoniRegexpFunctions.java#L120-L156","documentation":"Thrown by appendReplacement while rewriting regexp_replace output: the replacement string contains a '$' followed by a group reference or ${name} sequence that is not legal (unknown group name or malformed reference). The offending input is the replacement argument of regexp_replace, not the source string.","triggerScenarios":"Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/scalar/JoniRegexpFunctions.java:138 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Escape literal dollar signs in the replacement as \\$ (or \\\\$ in SQL string literals)","Reference only capture groups that exist in the pattern, e.g. $1 for (a)b","Use numbered groups $0..$n instead of ${name} unless names are defined"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}