In this article, we will outline how to use the functions RemoveFrom and RemoveUntil to optimize text using the expression engine.
Use case:
In certain cases, to simplify the process of cleaning the data in a given field you can remove text in bulk, from a given piece of text to the location of another piece of text.
Example of RemoveFrom()
Imagine all your product titles had the [ID at the end, but you don't want that sent to your Google Shopping or Facebook feeds. With RemoveFrom you can easily modify your data.
Your title:
Desktop PC with CDRW - 21
Apply the transformation expression RemoveFrom(field1," - ") to remove everything from " - ".
That will give you this title:
Desktop PC with CDRW -
You might not want to leave the " - " at the end of your titles. To remove the search string " - " add ",true" to the expression, so it looks like this: RemoveFrom(field1," - ",true)
Here is how it works:
The command:
RemoveFrom(field1,"text")
and if you wish to include the text
RemoveFrom(field1,"text",true)
Example of RemoveUntil()
In case the text you wish to remove is located in the beginning of your chosen field, the logic is exactly the same as in the example above.
Your title:
text additional information/1425XWYZ - Desktop PC with CDRW
Apply the transformation expression RemoveUntil(field1," - ") to remove everything until " - ".
That will give you the title:
- Desktop PC with CDRW
And as above, if you wish to remove " - ", add ",true" to the expression.
Here is how it works:
The command:
RemoveUntil(field1,"text")
and if you wish to include the text
RemoveUntil(field1,"text",true)
You can combine the function RemoveUntil/RemoveFrom with other functions to optimize your data even further.