Count the number of matches for a certain regex in a string column (avoiding java snippet node)

Hi guys,

I want to do something very easy in theory but currently I cannot find the way to do it without using java snippet node.

I want to simply count the number of matches for a certain regex in a string column. Anyway in the string manipulation node there are:

1. a RegexMatcher method that gives only “true” or “false” without counting the number of times

2. a count method that can be used to count characters but is not possible to use with a regex

Please, do you have any suggestion?

Gio

Hello Giovanni,

I have an idea, maybe not the best, but still an idea that should work.

First use a string replacer, your pattern will be your regex and replace the whole string using something that makes sense to you. Then simply use a groupby with a unique concatenate with count method.

Of course, this works only if you have 1 occurence of your regex in each row in the initial column.

Hope this helps.

Nicolas

Hi Nicolas,

Thank you for your suggestion. Finally I used 2 string manipulation nodes: one to match & replace the regex; and the second to count the replacements. This works also for multiple occurrences but I don't like because I consider it a dirty and dangerous workaround.

It's seems strange to me that in KNIME doesn't exist anything to do this in a clean way. Maybe we're missing something.

Anyway thank you again!

Gio

Counting the number of matches for a certain regex would be a very usefull feature!