regexMatcher Syntax not working

I have the following expression: ^Node \d{1,}$

This expression works when tested with regexr.com

But when I apply the expression into the regexMatcher expression in the String Manupulation node it doesn’t work.

regexMatcher($Row0$, "^Node \d{1,}$")

Is there anything that I am missing?

Welcome to the forum, @BruceV.

From your post it’s not clear at all what you’re trying to accomplish.

We don’t know what text you’re trying to process, and we don’t know what “it doesn’t work” means.

When asking for help, it’s best practice to provide as much detail as possible, including example data and a sample of your desired output.

My guess is that the issue is your inclusion of the end of line character, but I can’t say for sure without seeing the data.

@BruceV

You need to escape the \ backslash character. So, replace \ with \\.

You may find it easier to replace the \d with [0-9] and {1,} with + so your expression becomes ^Node [0-9]+$.

DiaAzul

3 Likes

This works, thank you!

Do you have any background why we need to use the double backlash?

Hi @elsamuel,

In the future I will provide more details into my ask.

Best,
BruceV

1 Like

Hi @BruceV,

The double-backslash is something that not surprisingly catches a lot of people out. It is to do with the way the string is passed down to the underlying programming language, and each “layer” of interpretation tries to treat the backslash as an “escape”, so we need to add additional backslashes to pass it down correctly, by “escaping the escape character”.

A further problem in KNIME is that it is not consistent across different nodes, but the main thing to be aware of is that it can be a problem, and so something to look out for

The following similar forum thread may assist further:

1 Like

@BruceV

Do you have any background why we need to use the double backlash?

The following Wikipedia entry provides a good overview.

2 Likes

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