Remove square bracket from the Column Cells

Hi Team

Can you help to guide me how to remove the square bracket from the column cells using string manipulation.

Tried remove character not working as expected.
Input
[/Users/Hub_Admin/Example Workflows/Basic Examples/Test_Session(2)]

output
/Users/Hub_Admin/Example Workflows/Basic Examples/Test_Session(2)

Additionally can we able to insert one additional word (development) using “Join” expression into the above output as
/Users/Hub_Admin/Development/Example Workflows/Basic Examples/Test_Session(2)

There are probably more elegant ways, but this works. There are two branches. The first works if the the number of characters before the split is fixed. If it changes this won’t work. The second will work if the first split has a variable length but still depends on “Example” being present in the path. The two paths also show two ways to remove the brackets. Hope this helps.

1 Like

Here’s a single node, RegEx-based solution with either String Manipulation or Column Expressions:
image

With String Manipulation, we can do:
replace(replace($TargetColumn$, “/Hub_Admin/”, “/Hub_Admin/Development/”), “[”, “”)

With Column Expressions:
regexReplace(
regexReplace(column(“TargetColumn”), “/Hub_Admin/”, “/Hub_Admin/Development/”),
“\[|\]”, “”
)

3 Likes

Hello @Ashwath5245,

You can use a String Manipulation node and write an expression like:

“replace(replace(regexReplace($column1$, “\[|\]”, “”), “/Hub_Admin/”, “/Hub_Admin/Development/”), “]”, “”)”

Output:

Screenshot 2024-02-19 115320

2 Likes

Hi tqAkshay95

I tried the expression not works and getting the below warning.

Thanks for the reply. Tried replacing the expression you given similar for another column but getting java characters. Do i need to change the column type to String format? Please advise.


image

1 Like

Not a bad idea to convert to string first, since after all you are telling Column Expressions it is of String type.

Hello @Ashwath5245

You can just copy and paste this expression:

replace(replace(regexReplace($workflowPath$, “[|]”, “”), “/Hub_Admin/”, “/Hub_Admin/Development/”), “]”, “”)

1 Like

Thanks tqAkshay95 for your reply. I think I am missing somewhere with related to variable or string which causing the warning

I have tried the expression you gave and got the error.

KNIME AP version 4.7.7

Output of the previous node

Hello @Ashwath5245

You need change data type to string.

1 Like

Hello @Ashwath5245

Your data type looks like ‘list’, this is why the square brackets are displayed; you would need to ungroup it in first instance:

You can use a String Manipulation afterwards aiming to insert ‘Development’ folder in your path address.

BR

1 Like

Hello @Ashwath5245

You can use java snippet node and write a code like

String inputString = c_AggregatedValues;

String withoutBrackets = inputString.replaceAll(“\[|\]”, “”);

String output = withoutBrackets.replace(“/Hub_Admin/”, “/Hub_Admin/Development/”);

out_AggregatedValues = output;

Output:

Thanks tqAshay95 for the efforts and suggestions. Much appreciated.

@gonhaddock - Excellent, you found the correct point. After ungrouping, the “[” removed properly and used the string manipulation to replace with the additional words.

Thanks All for your inputs and suggestions.

1 Like

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