string manipulation not working with "pre created" regular expressions

In my tabular data I have need to remove a substring from a column. The substring is specific to each row. The substring (or “removestring”) is given in another column within the same row and the substring must only be removed once.
In principle the regexreplace function does what I need, however only if I specify the regular expression individually per each row, like this:
regexReplace($headw-ex$,“(?<!removestring.)removestring" ,“” )
result here is correctly removing removestring from e.g. “stringwithremovestringremovestring” to “stringwithremovestring”.
The second row with another substring would require another regex and so on.
So in order to run through the whole table I am creating the regular expression upfront per each row in a column which I named “regex”.
if I configure the string manipulation node now like this:
regexReplace($headw-ex$ , $regex$ , “” ) it will not work! The column “regex” contains this content "(?<!removestring.
)removestring”
however no removal is done. So the behaviour of the regex replace function is different in case I do not explictly write the reqex within the node, but supply it via column content.

Hi @matthias.albus , I think generally it would be better to upload a small demo workflow that shows the problem you are having, because when I follow the steps you describe above, it seems to work. Perhaps you have a typo in your regex? Or perhaps included the double quotes?

regex replace using value from column.knwf (10.6 KB)

Hi @takbb , thanks for looking into this. I just realize that there is a missing character in the regex I posted, the correct example regex should read:
regexReplace($headw-ex$,“(?<!removestring.)removestring" ,“” )
as written in my description the “removestring” must only be removed once, if I wanted to have all occurrences of “removestring” being removed the “replace” function would have been easier to apply.
In any case I created a demo workflow that shows my use case with some fake data that is being created as part of the workflow.
regex_replace_using_substring_from_another_column.knwf (47.0 KB)
As you commented on it: I had tried two approaches: quotes in the regex column, and as part of the expression in the manipulation node, I got neither to work.

here is a table with what I want to achieve:

removestring headw-ex regex desired result
removestring1 somestringremovestring1 (?<!removestring1.*)removestring1 somestring
deletestring2 somestringdeletestring2 (?<!deletestring2.*)deletestring2 somestring
superfluousstring3 somestringsuperfluousstring3 (?<!superfluousstring3.*)superfluousstring3 somestring
removestring1 somestringremovestring1removestring1 (?<!removestring1.*)removestring1 somestringremovestring1
deletestring2 somestringdeletestring2deletestring2 (?<!deletestring2.*)deletestring2 somestringdeletestring2
superfluousstring3 somestringsuperfluousstring3superfluousstring3 (?<!superfluousstring3.*)superfluousstring3 somestringsuperfluousstring3

Hi @matthias.albus , I don’t know why, but you were adding double quotes and single quotes around the column name in the regexReplace.

In your example uploaded flow, the final String Manipulation will work if you change it …

from

regexReplace($headw-ex$,"'$regex$'" ,"" )

to

regexReplace($headw-ex$,$regex$ ,"" )

1 Like

Hi @takbb,

I was sure that I had tried that variant as well, as first attempt, actually.
No idea what I might have done wrong, but now it works indeed. The attempt with quoting twice was just a frustrated attempt.
Anyway, thanks!

best

Matthias

1 Like

Hi @matthias.albus. I think we all have moments like you describe. I certainly do, lol.
Glad to hear it’s working for you now.