String Manipulation with RegExMatcher (IF-Else/IF-Switch)

Hello,

I use a IF-Switch Node in my Workflow. To control the active port I use are StringManipulation Node.
The Expression is as follows:

regexMatcher($Content$,"[^a-zA-Z][0-9]") == “True” ? “top” : “bottom”

It should be checked if the Content Column (String) have numbers.
Is a number found, then the top branch should be executed and if no number was found, then the bottom branch. But the rule reports on every column a “True”, even no number can be found.

Thanks and BR,
Sven

I have had the opposite problem with regex always reporting false! So I’ll follow this thread to see if there is any advice for me, too. I have checked mine here: https://regex101.com/

Have you tried that with some sample values? (it works for me there, but not in Knime)

Hi
Have you tried using the Column Expressions node for this?
Also can you post some sample data? I think there is a problem in your regex, you need to create one that matches the whole string of the column you are testing, so if you want to match rows containing numbers anywhere in their string use something like: .*\\d+.* ( note to the double backslash, you need to do that to ensure the backslash reaches the regex engine).

best,
Gabriel

2 Likes

Hi @gab1one,

thanks for your reply. I noticed that I was missing the Column Expression Node.
Content
Row0 Rechnungsdatum: 27.07.2017
Row1 Rechnungs Nr. / Datum / Beleg Nr.
Row2 Kundennummer: 1234567

Row0 -> top
Row1 -> bottom, because the numbers I need are stored in a second column.
Row2 -> top

I also tried it with one of this regex-editors on the www and the result was:
Capture-regex

BR,
Sven

Hi @sven-abx,

To get the regex matcher to work like you seem to expect it to, you need to enter a regex that matches the whole string. You can test this easily with e.g. regex101, if the whole word / line is highlighted blue you are good to go. I would add some test strings for both cases so you can quickly see that your regex works as expected.

best,
Gabriel

1 Like

Hello @gab1one,

It’s working with:

var con_exp = column("Content");
var con_tof = regexMatcher(con_exp,".*\\d+.*" );

if (con_tof == 1) {
  port = "top";
} else {
  port = "bottom"
} 

thanks for your help!

br,
Sven

3 Likes

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