Return value from same row depending on value in other column

Hi KNIME community - I’d like help making a workflow to read a value in columnA and return a value from ether column B or C in the same row depending on the regex evaluation. (And write this value to a new column.) I have the regex logic but I don’t know what nodes would be best to use.

Starting Table:

Experiment String A String B
2126b abc foo
2135a def bar
2137a ghi baz
2138b jkl foo1
2145a mno bar1
2145b pqr baz1
2237a stu foo2
2245a vwx bar2

Rules:
If experiment matches regex \d{2}(?<=21)[0-3].{2}
(in my example, 2126b, 2135a, 2137a, 2138b)
then write to new column “String” using value from column “String A”

If experiment matches regex ^\d{2}(?(?<=21)[4-9].{2}|.{3})
(in my example, 2145a, 2145b, 2237a, 2245a)
then write to column “String” using value from column “String B”

Ideal output:

Experiment String
2126b abc
2135a def
2137a ghi
2138b jkl
2145a bar1
2145b baz1
2237a foo2
2245a bar2

Unfinished workflow with starting table created:
sandbox.knwf (12.6 KB)

Thanks,
Amy

Solved my own problem with a little more effort spent.

I used an if statement in a Column Expressions node (I didn’t need to use the second regex)

if (regexMatcher(column(“experiment”),"\d{2}(?<=21)[0-3].{2}"))
column(“StringA”)
else
column(“StringB”)

sandbox_solved_final.knwf (11.1 KB)

4 Likes

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