Hey everyone,
So, these words " in " , " for ", " hand " & " cars " along with space at the beginning and end are substrings to be replaced with a single space in a string
Here’s the regex, I used in the string replacer node using or (|)
Hi @Ummehaani , this is probably because of the spaces you are adding, it will find (and replace) only 1 of the the list. I understand why you want the spaces included, but I don’t know how to do this in Regex - and it looks like neither do you
In that case, why not just use regular replace() via String Manipulation like this?
replace(replace(replace(replace($Keyword$
, " in ", " ")
, " for ", " ")
, " hand ", " ")
, " cars ", " ")
Hi @Ummehaani, I think @bruno29a is right that part of the problem you had is because of the spaces. The string replacer is trying to find a word wrapped with spaces, but having also replaced the spaces, it then doesn’t find a neighbouring word that is also wrapped with spaces.
You could try using regex “word boundaries” instead which are represented by \b
\bcars\b|\bin\b|\bhand\b|\bfor\b
This would find your keywords whenever they are separate words, and not just when surrounded by spaces.
That doesn’t then remove the surrounding spaces though, if present, so you might have to follow it with a further String Replacer whose job it is to replace two spaces with one space.
Alternatively, @bruno29a’s solution works well too as a single node, and might be more straightforward
Hi @lenexa_jayhawk , this probably works for these specific text, but probably won’t work with other texts.
One of the reasons I added the “handsome cars” was to show that the “hand” part from “handsome” would not change, and it still works here with your "|hand " rule simply because “handsome” qualifies, but I think the original idea was to look for “hand” as a word, or “cars”, or “in” etc as words.
So, in your case, if you have a text like “within cars”, the "within " will be changed to “with” because incidently, "within " will match "in ". Similarly if you have a text like “forehand cars”, the “forehand” will be changed to “fore”. So this will not match the strings as words, but rather as substrings.