Search code examples
javastringcomparisonknime

KNIME: Compare if One Column Contains a subset of another column


In Knime I am trying to compare if a value in one column is contained within another column. I tried to do this using "LIKE" in the Rule Engine but couldn't get the wildcards to work with a column input instead of a string. E.g.

For row1 I want to check if column 1, row 1 is within column 2, row 1
For row2 I want to check if column 1, row 2 is within column 2, row 2

Like is "ABC" contained within "test ABCtest"

Does the "LIKE" in Rule Engine only allow hard coded strings for comparison? Other ideas to achieve this? Thank you for the help!


Solution

  • The String Manipulation node with the regexMatcher can help here, though the result will be String (with values True/False by default), so further node will be required if for example a number is required (if different String, you can use the ?/: ternary operator like == "True" ? "when true" : join("when false it was because '", $columnReference$, "' was not found")).

    You can use regexMatcher like this (\Q/\E helps to avoid treating the content in Reference column as a regular expression (except when it contains \E)):

    regexMatcher($text$, join(".*?\\Q", $Reference$, "\\E.*+")) == "True" ? "vrai" : "faux"
    

    regexMatcher($text$, join(".*?\Q", $Reference$, "\E.*+"))