Delete last occurence of a character

Hi,

I am having a hard time deleting the last comma of a string. Regex should work with
replace($column1$, "(.*),", "") in a String Manipulation node.

grafik

grafik

However nothing happens if I use it like this. Any idea? Thanks for your help!

Hi @Awiener

You could use the following trick here as follows:

  1. use the replace() function to replace commas “,” by spaces " "
  2. use then them trim() function to trim any blank at the begining and end of your string.
  3. replace blanks back with the commas.

This should do the trick:

replace( trim( replace( $your string$, ",", " ")), " ", ",")

Hope this helps.

Best Ael

PS: I’m answering from the smartphone so sorry I cannot provide you with a workflow as example.

5 Likes

Hello @Awiener
First of all, the string manipulation function has to be regexReplace()
As you are trying to replace excluding the comma, and you already defined a capturing group (brackets), then the capturing group should be the repacement “$1”.

Summarizing.
I’m not in a computer right now (answering from mobile as well), but you can test the following expression:
regexReplace($column1$, "(.*),", "$1")

BR

6 Likes

Thanks @gonhaddock, that’s it! :wink:

and thanks to @aworker, sounds great too.

2 Likes

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