HOW TO MODIFY ONLY A PART OF A CELL

Hello everybody!

I’m having some trouble with a regular expression. I need to replace only a part of a cell, the problem is that can be writen in differents ways. Example:

SNOOPY THE DOG
SNOPY THE DOG
SNOOPY DOG
SNOOP DOGG

I need to keep the word “DOG” but also have to modify the “SNOOPY” variables. I tryed with a string manipulation and this regex:

regexReplace($FAMILYFRIENDLY$, “SN.*”, “SNOOPY”)

Thanks for reading and hope to find a solution for this!

Hi @Tripaflaca , it would help if you could show us what the expected results of the given sample data would be.

So far, you have only showed us what you tried and it’s not giving the expected results, so we have no idea what the expected results you are looking for.

Hi! Thanks for answering and sorry, its hard to explain but here is an example:

The lenght of the word “SNOOPY” in the first column can change, people who charge the information sometimes miss or add a letter, thats why i need a regex to include the most types of variations. Then I will check all the base and fix those cases where the regex couldnt fix the error.

You could use the cell splitter node or Regex to divide this into 2 columns. 1 with the first work and a second with the remaining string. Then you can do fuzzy match on the first word and then re-combine the changes with the second half of the string.

2 Likes

It is guaranteed that it will always be the first word? :slight_smile:

Hi @Tripaflaca , using your regex example as you have it, it will try replacing the entire string beginning with “SN” with SNOOPY, irrespective of word boundaries.

Try the following in string manipulation

regexReplace($FAMILYFRIENDLY$, "\\bSN.*?\\b", "SNOOPY")

What this does is tell string manipulation to find any occurrence of SN after a “word boundary”, and then matching all letters up to the first next word boundary. The ? quantifier tells it to find the minimal matches to meet this criteria. This means it matches only up to the first word boundary, and not the entire string.

The \\ are required in String Manipulation instead of just a single \ because of the way the parsing of the string works.

image

6 Likes

My first idea was string similarity but @takbb s regex example is really good.
br

1 Like

Thanks all for answering. The solution for my problem was given for @takbb but i also found interesting the replay of @iCFO , I will use that solution for other cell i got that has lots of words and maybe a regex for that would be difficult.

I also found some regex formulation help in this link regex - Regular expression to match string starting with a specific word - Stack Overflow (Tittle: “Regular expression to match string starting with a specific word” of the page https://stackoverflow.com/ if you dont want to clic the link for security)

That post also helped me with some characters im not used to work with. Hope this post help more pleople!

Thanks again to everybody :heart: !

2 Likes

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