3

I'm trying to remove the content of all cells that start with a character that is not a number using KNIME (v3.2.1). I have different ideas but nothing works.

1) String Manipulation Node: regexReplace(§column§,"^[^0-9].*","")

The cells contain multiple lines, however only the first line is removed by this approach.

2) String Manipulation Node: regexMatcher($casrn_new$,"^[^0-9].*") followed by Rule Engine Node to remove all columns that are "TRUE".

The regexMatcher gives me "False" even for columns that should be "True" though.

3) String Replacer Node: I inserted the expression ^[^0-9].* into the Pattern column and selected "Replace whole String" but the regex is not recognised by that node so nothing gets replaced.

Does anyone have a solution for any of those approaches or knows another Node that might do the job? Help is much appreciated!

4

2 回答 2

4

我会选择你的第一个解决方案,因为它已经工作了,你只需要扩展你的正则表达式以包含换行符。我会尝试这样的事情:

regexReplace($column$,"^[^0-9].(.|\n)*","")

这应该匹配以非数字字符开头的任何文本,后跟任意字符或换行符的出现次数。根据行尾,您可能需要(.|\n|\r)代替(.|\n).

于 2016-10-13T07:41:35.470 回答
1

您应该使用以下表达式:

"(?s)^\D.*$"

所以这个点甚至会匹配新的行。(基于此:https ://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html#DOTALL )

如果您只需要更改不以数字开头的单元格的内容,我认为您不需要过滤任何列或行。(顺便说一句,如果您想删除行,有基于规则的行过滤器/拆分器节点,它们也支持带有 MATCHES 谓词的正则表达式。)

于 2016-10-13T07:41:25.110 回答