US and Worldwide: +1 (866) 660-7555
Results 1 to 2 of 2

Thread: JavaScript: how to use split function with backslashes?

  1. #1
    Join Date
    Jul 2007
    Posts
    247

    Default JavaScript: how to use split function with backslashes?

    Hi everybody,

    I'm trying to use the split function in the modified javascript step to split a string which contains backslashes (e.g. "C:\WINDOWS\SYSTEM32").

    I tried:

    Code:
    var dirs = DIR_NAME.getString().split("\\");
    but this will result in the following exception:

    Code:
     Javascript error: org.mozilla.javascript.WrappedException: WrappedException of Unexpected internal error near index 1
     \
      ^
     Error stack trace: 
     org.mozilla.javascript.WrappedException: WrappedException of Unexpected internal error near index 1
     \
      ^
         at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1604)
         at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:191)
         at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:202)
         at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1442)
         at org.mozilla.javascript.gen.c5._c0(script:2)
         at org.mozilla.javascript.gen.c5.call(script)
         at org.mozilla.javascript.gen.c5.exec(script)
         at be.ibridge.kettle.trans.step.scriptvalues.ScriptValues.addValues(ScriptValues.java:131)
         at be.ibridge.kettle.trans.step.scriptvalues.ScriptValues.processRow(ScriptValues.java:191)
         at be.ibridge.kettle.trans.step.scriptvalues.ScriptValues.run(ScriptValues.java:230)
     Caused by: java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
     \
      ^
         at java.util.regex.Pattern.error(Pattern.java:1650)
         at java.util.regex.Pattern.compile(Pattern.java:1403)
         at java.util.regex.Pattern.<init>(Pattern.java:1124)
         at java.util.regex.Pattern.compile(Pattern.java:817)
         at java.lang.String.split(String.java:2103)
         at java.lang.String.split(String.java:2145)
         at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:174)
         ... 8 more
    Am I missing here something? I'm using PDI 2.5.2


    Thx in advance,
    Ben

  2. #2
    Join Date
    Nov 1999
    Posts
    9,677

    Default

    IIRC, Regular expressions (used in split) need backslashes to be doubled too, as such, you end up with something like split("\\\\")
    Matt Casters, Chief Data Integration
    Pentaho, Open Source Business Intelligence
    http://www.pentaho.org -- mcasters@pentaho.org

    Author of the book Pentaho Kettle Solutions by Wiley. Also available as e-Book and on the Kindle reading applications (iPhone, iPad, Android, Kindle devices, ...)

    Join us on IRC server Freenode.net, channel ##pentaho

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •