IN or INCLUDES via Column Expressions

Happy Monday!

I am trying to write an ‘if contains’ statement. I would like to write the statement in the Column Expressions tool but it does not look like it supports it.

Does the JavaScript IN or INCLUDES work in the Column Expressions tool?

For Clarification I have strings that looks like this (John Smith[Recruiter](Jane Smith)[HR Manager]. My contains would just look for “HR Manager” The LIKE function in the Rule Engine is not picking “HR Manager” out of the string.

2 Likes

Hi,

In Rule Engine node you can use this to match the string:
$column1$ LIKE "*HR Manager*" => TRUE

Or in Column Expressions node you can use this:
if (regexMatcher(column("column1"), ".*HR Manager.*")) true

Is it what you want or I’m missing something?

Best,
Armin

3 Likes

@armingrudd

Thank you for the reply. For whatever reason the Rule Engine node is not working to identify the “HR Manager” string within the larger string of (John Smith[Recruiter](Jane Smith)[HR Manager]. To make matter worse, the string lengths vary with the piece i’m looking for showing up in different parts of the overall string.

I tried the (regexmatcher) in the Column Expressions node and I think I have the same problem. It’s marking all at true, regardless of the string.

Would you please provide an example of your input and desired output here?

@armingrudd
I am essentially trying to write something like this:

if
(regexMatcher(column(“Req Team”), “.HR Manager.”))
&& regexMatcher(column(“Req Team”), “.Recruiter.”)) {
‘Yes’
}else{
‘No’
}

It is may not be simultaneously HR Manager and Recruiter in the same field.
So,
if
(regexMatcher(column(“Req Team”), “ .HR Manager. ”))
|| regexMatcher(column(“Req Team”), “ .Recruiter. ”)) {
‘Yes’
}else{
‘No’
}

Will work better.

@izaychik63,

So what’s strange is, the regexMatcher is not applying a FALSE or a “No” when the text is not contained in the string. It is putting a TRUE or a Yes for each row in the entire column.

The Rule Engine works with this expression no problem:

$Req Team$ LIKE “HR Manager” OR $Req Team$ LIKE “AB123” => “Yes”
TRUE => “No”

Unfortunately I cannot get the regexMatcher to do the same thing. I just want to keep these statements consolidated in the Column Expression node. I must be missing something!

As LIKE analog I would use IndexOf() function.

Hi @izaychik63. My need is to do a ‘Contains’ function and i was under the impression the LIKE was the KNIME equivalent. Is this correct? Do you have an example of how I would use Index to identity text in string of varying lengths? I’ve actually never used the function before. Or if you could point me to a resource

1 Like

I have a few examples put together (also from the discussion here)

kn_example_regex_matcher.knwf (11.9 KB)

2 Likes

@mlauber71

Thank you! This is great. I will work through my problem with my data set and let you know.

1 Like

You could do even more fun stuff with Regex :slight_smile:

if (regexMatcher(column("var1"), "^(?=.*?(HR Manager|hr manager))(?=.*?(Recruiter)).*$") ) true; if (regexMatcher(column("var1"), "^(?=.*?(Recruiter))(?=.*?(HR Manager|hr manager)).*$") ) true; else false; /* http://dominounlimited.blogspot.com/2007/09/using-regex-for-matching-multiple-words.html */

@mlauber71

For sure! Regex is an area that I’m not very familiar with and feel like my work would benefit greatly if I became more fluent in it.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.