Search if a text ends with a specific string

Hello, I would like to search for specific values where the occurrence happens at the end of a string only, so for example, in QWE51-B75-B, I’d to get the last -B.

I can manage to retrieve the last occurrence if i use indexof with “b” as a modifier, but if I have a reference like this one, QWE51-B75-B3, the function will output a positive value instead of -1.

For instance, in M there is a function called Text.EndsWith that does this, is there a specific function or an alternative that can be applied within KNIME?

Best regards,

Hi @sirabelk3 , you can use Regex to verify if the rows of a column ends with a specific string.

If you explain what you are trying to do with some sample data, I am sure a lot of people can help you. From what you have given, I have no idea what you are looking for, and what your use case is. It wuld help to know what’s your input data, what’s your expected output data.


@sirabelk3 there is the lastIndexOfChar() function from Column Expressions you could combine with something. But as @bruno29a has said: you might have to more clearly define your task and also consider edge cases (no “-”, double “–”, special characters) …


@mlauber71 that’s the function I was looking for, I feel dumb for missing it haha now as you said I can combine it with other functions to meet the condition. Thanks for the workflow.

@bruno29a I tried with regex but as I have more than 20 conditions with different digits in a list of thousands records I ended giving up when I was unable to get the results I expected, but I will try to practice regex.

Many thanks to you both!

1 Like

@sirabelk3 the Column Expression can be done in one node. I have just split it to make it more readable.

1 Like

Hi @sirabelk3

I’m not sure I understand. What 20 conditions do you have? Would you not face the same issue with lastIndexOfChar() function (which is the function you were looking for)? Usually, Regex would actually solve this kind of issue as it’s able to apply multiple patterns at once while lastIndexOfChar() can only search for 1 specific string at a time.

1 Like

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