pentaho/pentaho-kettle · error · JavaScriptException
The function call str2RegExp requires 2 arguments.
Error message
The function call str2RegExp requires 2 arguments.
What it means
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.
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.
Example fix
// before
var parts = str2RegExp('a1b2c1');
// after
var parts = str2RegExp('a1b2c1', '(\\d)'); Defensive patterns
Strategy: validation
Validate before calling
if (inputStr == null || pattern == null) throw 'str2RegExp: missing argument'; var parts = str2RegExp(String(inputStr), pattern);
Type guard
function canStr2RegExp(s, p) { return s != null && p != null && String(p).length > 0; } Try / catch
try { var parts = str2RegExp(String(inputStr), pattern); } catch (e) { var parts = []; } Prevention
- 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
When it happens
Trigger: Calling str2RegExp() with one argument only (string but no pattern), or three or more arguments, in a modified JavaScript step.
Common situations: Adapting examples from other regex-split APIs, forgetting the pattern argument, or building the pattern dynamically and accidentally passing extra arguments.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Error in isEmpty function:
- Function call replace is not valid :
- Script.Log.CouldNotAddDefaultConstants
- ScriptValuesMod.Log.CouldNotAddDefaultConstants
- ScriptValuesMod.Log.CouldNotCompileJavascript
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/302efd36aabe6e7e.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:976
if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
return null;
} else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
return Context.getUndefinedValue();
}
String strToMatch = Context.toString( ArgList[0] );
Pattern p = Pattern.compile( Context.toString( ArgList[1] ) );
Matcher m = p.matcher( strToMatch );
if ( m.matches() && m.groupCount() > 0 ) {
strArr = new String[m.groupCount()];
for ( int i = 1; i <= m.groupCount(); i++ ) {
strArr[i - 1] = m.group( i );
}
}
} catch ( Exception e ) {
throw Context.reportRuntimeError( e.toString() );
}
} else {
throw Context.reportRuntimeError( "The function call str2RegExp requires 2 arguments." );
}
return strArr;
}
public static void touch( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
try {
if ( ArgList.length == 1 && !isNull( ArgList[0] ) && !isUndefined( ArgList[0] ) ) {
File file = new File( Context.toString( ArgList[0] ) );
boolean success = file.createNewFile();
if ( !success ) {
file.setLastModified( System.currentTimeMillis() );
}
} else {
throw Context.reportRuntimeError( "The function call touch requires 1 valid argument." );
}
} catch ( Exception e ) {
throw Context.reportRuntimeError( e.toString() );View on GitHub (pinned to f3058517a1)