I am using a field from a data extension for a personalization string within an email.

And some of the data in the field is set as "3x6 (unfinished)" or "3x6 (no grommets)". How can I set the personalization string to remove the paranthesis and the text within the paranthesis? So in this case just keep "3x6".

Here's what I have so far:

%%[var @favoriteSize_name
set @favoriteSize_name = AttributeValue("favoriteSize_name") 
set @favoriteSize_name = favoriteSize_name
IF @favoriteSize_name CONTAINS("(unfinished)" OR "(no grommets)" then
set @favoriteSize_name = 
endif ]%%

1 Answer 1


You are close, but AMPscript does not have a CONTAINS function or operator. What you have to use instead is IndexOf().

So you would do something like:

  set @favoriteSize_name = AttributeValue("favoriteSize_name") 
  SET @unfinishedIndex = IndexOf(@favoriteSize_name, "(unfinished)")
  SET @noGrommetIndex = IndexOf(@favoriteSize_name, "(no grommets)")
  IF @unfinishedIndex > 1 THEN
    SET @favoriteSize_name = Substring(@favoriteSize_name, 1, Subtract(@unfinishedIndex,1))
  ELSE IF @noGrommetIndex > 1 THEN
    SET @favoriteSize_name = Substring(@favoriteSize_name, 1, Subtract(@noGrommetIndex,1))

This would then do a substring based on the index if the index of those two strings are greater than 1. This will remove those strings and any information following that. This is great for if you want to remove anything beyond a certain char or phrase.

If you have something that exists in the middle of your text or is very specific that you want to remove, you can instead utilize replace.

  set @favoriteSize_name = AttributeValue("favoriteSize_name") 
  SET @favoriteSize_name = ReplaceList(@favoriteSize_name, "", "(no grommets)", "(unfinished)")


So as you want to remove it, you would just do a Replace with an empty string. Now as there are multiple things you want to replace with an empty string, rather than do multiple replaces, we can use the ReplaceList() function instead.

  • 1
    Thanks @Gortonington, I was able to make the first statement work for my use case.
    – Bia
    Oct 21, 2021 at 21:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .