Search code examples
escapingknime

Unable to properly escape rules in KNIME


I use a "table creator" to create a list of rules which are then fed to a "rule-based row splitter (dictionary)"

The rules are of the form:

$colname$="somevalue"    TRUE

I have created this setup multiple times already and it is working fine. However, some of the string values I need to compare contain doublequotes. According to the official documentation, they need to be scaped using a backslash. I tried that in various permutations, but it always fails.

Error message:

ERROR Rule-based Row Splitter (Dictionary) 0:228      Execute failed: 
java.text.ParseException: Line: 306: Expected: =>
$value$="2\"" => TRUE

Rule formating, I've tried, all failed:

$col$=5"
$col$=5\"
$col$="5""
$col$="5\""

According to the docs, the last one should be the correct syntax but it also fails with the above error code. What am I doing wrong?


Solution

  • Found the answer after a long discussion in the KNIME forums. Posting the answer here for completeness sake:

    There are two problem cases here and the solution is to handle them separately, one by one.

    1) Your string contains doublequotes:

    This is forbidden by KNIME. Encapsulate your string in slashes like so:

    $colname$ = /and she said: "hi"/
    

    2) Your string contains slashes:

    Surround your string with doublequotes like so:

    $colname$ = "i need size 40 3/4"
    

    If you have both mixed inside the same string, you need to use code snippets.