{"record":{"id":"302efd36aabe6e7e","repo":"pentaho/pentaho-kettle","slug":"the-function-call-str2regexp-requires-2-arguments-302efd","errorCode":null,"errorMessage":"The function call str2RegExp requires 2 arguments.","messagePattern":"The function call str2RegExp requires 2 arguments\\.","errorType":"exception","errorClass":"JavaScriptException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":976,"sourceCode":"        if ( isNull( ArgList, new int[] { 0, 1 } ) ) {\n          return null;\n        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {\n          return Context.getUndefinedValue();\n        }\n        String strToMatch = Context.toString( ArgList[0] );\n        Pattern p = Pattern.compile( Context.toString( ArgList[1] ) );\n        Matcher m = p.matcher( strToMatch );\n        if ( m.matches() && m.groupCount() > 0 ) {\n          strArr = new String[m.groupCount()];\n          for ( int i = 1; i <= m.groupCount(); i++ ) {\n            strArr[i - 1] = m.group( i );\n          }\n        }\n      } catch ( Exception e ) {\n        throw Context.reportRuntimeError( e.toString() );\n      }\n    } else {\n      throw Context.reportRuntimeError( \"The function call str2RegExp requires 2 arguments.\" );\n    }\n    return strArr;\n  }\n\n  public static void touch( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    try {\n      if ( ArgList.length == 1 && !isNull( ArgList[0] ) && !isUndefined( ArgList[0] ) ) {\n        File file = new File( Context.toString( ArgList[0] ) );\n        boolean success = file.createNewFile();\n        if ( !success ) {\n          file.setLastModified( System.currentTimeMillis() );\n        }\n      } else {\n        throw Context.reportRuntimeError( \"The function call touch requires 1 valid argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( e.toString() );","sourceCodeStart":958,"sourceCodeEnd":994,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L958-L994","documentation":"The str2RegExp() JavaScript function splits a string into an array of matched tokens using a regular expression. It requires exactly 2 arguments (the input string and the regex pattern); with any other argument count it throws this runtime error.","triggerScenarios":"Calling str2RegExp() with one argument only (string but no pattern), or three or more arguments, in a modified JavaScript step.","commonSituations":"Adapting examples from other regex-split APIs, forgetting the pattern argument, or building the pattern dynamically and accidentally passing extra arguments.","solutions":["Call str2RegExp() with exactly 2 arguments: string and regex pattern.","Verify the pattern compiles as a valid Java regex.","Null-check the input string before the call.","Escape regex metacharacters in dynamic patterns."],"exampleFix":"// before\nvar parts = str2RegExp('a1b2c1');\n// after\nvar parts = str2RegExp('a1b2c1', '(\\\\d)');","handlingStrategy":"validation","validationCode":"if (inputStr == null || pattern == null) throw 'str2RegExp: missing argument';\nvar parts = str2RegExp(String(inputStr), pattern);","typeGuard":"function canStr2RegExp(s, p) { return s != null && p != null && String(p).length > 0; }","tryCatchPattern":"try { var parts = str2RegExp(String(inputStr), pattern); } catch (e) { var parts = []; }","preventionTips":["Always pass exactly 2 arguments: string and pattern","Escape metacharacters in dynamic patterns","Test the regex against sample data first","Null-check both inputs before calling"],"tags":["javascript","rhino","regex"],"backgroundTag":"missing-required-argument","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}