BruceV
October 2, 2022, 10:58am
1
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
BruceV
October 3, 2022, 7:14am
4
This works, thank you!
Do you have any background why we need to use the double backlash?
BruceV
October 3, 2022, 7:15am
5
Hi @elsamuel ,
In the future I will provide more details into my ask.
Best,
BruceV
1 Like
takbb
October 3, 2022, 8:33am
6
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:
Hi @Daniel_Weikert , I don’t think there is a list but in general the nodes that use are based on actual programming language need to add the extra backslash.
e.g. Requiring double-backslash:
String Manipulation, Column Expressions, Java Snippet
Not requiring double-backslash:
Rule Engine
Row Based Rule Filter
Regex Split
Column Rename (Regex)
For the “scripting” nodes, there is a small visual clue as the colour of the string changes. If the String is not displayed as red when you enter …
1 Like
@BruceV
Do you have any background why we need to use the double backlash?
The following Wikipedia entry provides a good overview.
In computing and telecommunication, an escape character is a character that invokes an alternative interpretation on the following characters in a character sequence. An escape character is a particular case of metacharacters. Generally, the judgement of whether something is an escape character or not depends on the context.
In the telecommunications field, escape characters are used to indicate that the following characters are encoded differently. This is used to alter control characters that ...
2 Likes
system
Closed
October 10, 2022, 8:52am
8
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.