String Manipulation

Hi,

I am really struggling with knime’s functionality to extract parts of a string. I have attached some images

I would like to extract 2 parts from this string: Q:\Strategy Deployment\B100+ Tableau Files\1 - Data Store\2025\Brand\test initiative.xlsx

I would like Brand to be a new column called “action field” and test initiative to be new column called “initiative”.

I have been able to successfully extract the initiative column however can’t seem to extract the action field in a logic driven automated way.

In past experience using other tools there was a way to "take everything to the right of the second " however I can’t seem to find a way to get the index of the nth character.

Hi there,

I think there are two ways to achieve this, provided that the path and the number of slashes in it always stays constant.

  1. Use Cell Splitter and split by “\” as delimiter
  2. Use Regular Expressions (using Expression node)

Here’s a prototype:

PathRegex.knwf (79.4 KB)

I will admit that I first asked ChatGPT how to match the parts of your string. I then used that as input into my prompt to K-AI in Expression Node. Reason for doing that is that you need to escape "" and the Regex Expressions have a lot of them :smiley:

3 Likes

Hi @finspencer246 ,

If I understand well, you have a “file”, with a path that you need t9o split it and select some “columns” from the path.

If you use csv reader or List/folders node, to bring from a path, all files as subdirectories. Than you can use cell split to create columns.

But you have to stay with the same structure to reuse the operation with a batch process/automation.

I hope that it helps you.

Thanks, Denis

Hi,

how about using “indexOf” to get the position of the last “\”?

Using two addional “string manipulation” nodes will get you the desired “Brand” column. If you like you can combine both nodes to one, but then it’s hard to read.

1 Like

Nice one Martin!!

This is exactly what I was looking for. This node will be very useful going forward, thank you.

Glad it worked for you!

If you don’t mind please flag the post as solution - that way people that came across this topic when searching for a solution to a similar problem see it at the top of the page.