Out of curiosity, how is $1 means original column name in KNIME?
Also, I have 4 column names and if I want to exclude those names while renaming (usually there are 12-15 columns present in each file), what is the syntax for that?
Let’s say, apple, banana, baby and ox are the four names
I saw and tried the document given in the node help page. I couldn’t figure out.
I know, I can do this using Column rename and manually change this. But, I have to do this for 12 files.
OK, first the easy-to-explain part - in the matching pattern, (.+), ‘.’ matches any character, and ‘+’ means 1 or more of them, so ‘.+’ matches then entire column name. That match is surrounded by ‘(’ and ‘)’ which is, in regular expressions a capturing group (see https://www.regular-expressions.info/refcapture.html). In the replacement, ‘$1’ refers to the contents matched in the first capturing group - in this case the whole column name.
Now the more tricky part - excluding names. You can either use a Column Splitter node to separate the columns you dont want to rename from those you do, rename them as above, and then put them back together with a Column Appender node, or you can change your regular expression as follows:
(?!apple|banana|baby|ox)^(.+)
This works as follows - the first part enclosed in ‘(’ and ‘)’ is called a negative lookaheadhttps://www.regular-expressions.info/lookaround.html - the matching must start by not matching whatever follows the ‘?!’ sequence - ‘|’ meaning ‘or’. Now we come to ‘^’ which means ‘the start of the string’, and then the same ‘one or more of any character’ match we had previously. Without the ‘^’ you will get some very strange behaviour in this case.