AMPscript ReplaceList (Next)
Swap several search values for one replacement with AMPscript ReplaceList in Marketing Cloud Next. Syntax, examples, and behaviour proven in a Marketing Cloud Next email, including how it differs from Engagement.
Syntax
ReplaceList(sourceString, replacementString, searchString1[, searchStringN, ...]) → string
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
sourceString |
string | Yes | String to search in |
replacementString |
string | Yes | Text every match is replaced with |
searchString1 |
string | Yes | First value to look for |
searchStringN |
string | No | Any number of further values to look for |
At least three arguments, with no upper bound. Pass every argument as a string: a number or boolean literal breaks the render.
Example
%%=ReplaceList("a-b/c", "_", "-", "/")=%%
Renders a_b_c.
A value that arrived with mixed delimiters can be flattened in one call:
%%=ReplaceList("a,b,c;d", "+", ",", ";")=%%
Renders a+b+c+d.
Return value
string — the source with every match of every search value rewritten.
A source that none of the search values match comes back unchanged, and an empty source gives an empty string. Otherwise the result is free text, so there is no fixed set of special values to test for.
Behaviour
Three arguments is the minimum. An email containing ReplaceList(), ReplaceList("abc") or ReplaceList("abc", "z") cannot be saved: the content API answers HTTP 400 with “The AMPscript syntax isn’t valid”.
One search value is enough, and more are fine. ReplaceList("Hello World", "There", "World") gives Hello There. A seven-argument call swapping five digits in a1b2c3d4e5 for * gives a*b*c*d*e*.
Absent and repeated search values change nothing. ReplaceList("Hello World", "!", "zzz", "qqq") gives Hello World, and ReplaceList("aXa", "-", "a", "a") gives -X-: the second a finds nothing left.
Empty values are harmless. An empty replacement deletes every match: ReplaceList("a-b/c", "", "-", "/") gives abc. An empty search value leaves abc unchanged, and an empty source gives an empty string.
Numbers and booleans break the render. The email saves, but the preview fails (HTTP 500) when an argument is a bare number or boolean: ReplaceList(101101, "9", "0"), ReplaceList("a-b", 7, "-"), ReplaceList("a1b", "-", 1), ReplaceList(true, "X", "ru"), ReplaceList("a-b", true, "-") and ReplaceList("is true here", "X", true) all failed. Quote numeric values.
The search values run one after another
| Call | Renders |
|---|---|
ReplaceList("a", "XY", "a", "X") |
XYY |
ReplaceList("abc", "-", "ab", "bc") |
-c |
ReplaceList("abc", "-", "bc", "ab") |
a- |
ReplaceList("aaa", "a", "aa") |
aa |
ReplaceList("Red BLUE green", "-", "red", "blue", "GREEN") |
- - - |
Each search value works on the output of the one before it. In the first row a turns into XY, and the next search value then hits the X just inserted, giving XYY. So order matters: ab before bc leaves -c, the reverse leaves a-. Within one search value the scan is a single pass, so aaa with aa → a stays aa. Matching ignores case: ReplaceList("Hello World", "There", "WORLD") and ReplaceList("Cat cat CAT", "dog", "cat") give Hello There and dog dog dog.
Show Next test script
<!-- Marketing Cloud Next test script for ReplaceList. Paste it into the HTML component of a
Next email and open the preview. Each line prints the result Next gave when the call
was rendered on its own (expect) next to the result of this run (got).
Assembled from single-call test emails (dates on the page); it has not been
run as one email. Calls that make Next fail are listed separately. -->
<p>c1 expect=[aXbXc] got=[%%=ReplaceList("a-b_c","X","-","_")=%%]</p>
<p>c2 expect=[-c] got=[%%=ReplaceList("abc","-","ab","bc")=%%]</p>
<p>c3 expect=[XYY] got=[%%=ReplaceList("a","XY","a","X")=%%]</p>
<p>c4 expect=[a_b_c] got=[%%=ReplaceList("a-b/c", "_", "-", "/")=%%]</p>
<p>c5 expect=[a+b+c+d] got=[%%=ReplaceList("a,b,c;d", "+", ",", ";")=%%]</p>
<p>c6 expect=[Hello There] got=[%%=ReplaceList("Hello World", "There", "World")=%%]</p>
<p>c7 expect=[Hello There] got=[%%=ReplaceList("Hello World", "There", "WORLD")=%%]</p>
<p>c8 expect=[dog dog dog] got=[%%=ReplaceList("Cat cat CAT", "dog", "cat")=%%]</p>
<p>c9 expect=[- - -] got=[%%=ReplaceList("Red BLUE green", "-", "red", "blue", "GREEN")=%%]</p>
<p>c10 expect=[aa] got=[%%=ReplaceList("aaa", "a", "aa")=%%]</p>
<p>c11 expect=[a-] got=[%%=ReplaceList("abc", "-", "bc", "ab")=%%]</p>
<p>c12 expect=[Hello World] got=[%%=ReplaceList("Hello World", "!", "zzz", "qqq")=%%]</p>
<p>c13 expect=[abc] got=[%%=ReplaceList("a-b/c", "", "-", "/")=%%]</p>
<p>c14 expect=[abc] got=[%%=ReplaceList("abc", "X", "")=%%]</p>
<p>c15 expect=[] got=[%%=ReplaceList("", "x", "a")=%%]</p>
<p>c16 expect=[-X-] got=[%%=ReplaceList("aXa", "-", "a", "a")=%%]</p>
<p>c17 expect=[a*b*c*d*e*] got=[%%=ReplaceList("a1b2c3d4e5", "*", "1", "2", "3", "4", "5")=%%]</p>
Show calls that fail in Next (one email each)
<!-- Run each call below in its own Next email: one of them in a combined email
would stop the whole preview or block the save. -->
<!-- email 1: expect that the email saves, but the preview fails (HTTP 500) -->
%%=ReplaceList(101101, "9", "0")=%%
<!-- email 2: expect that the email saves, but the preview fails (HTTP 500) -->
%%=ReplaceList("a-b", 7, "-")=%%
<!-- email 3: expect that the email saves, but the preview fails (HTTP 500) -->
%%=ReplaceList("a1b", "-", 1)=%%
<!-- email 4: expect that the email saves, but the preview fails (HTTP 500) -->
%%=ReplaceList(true, "X", "ru")=%%
<!-- email 5: expect that the email saves, but the preview fails (HTTP 500) -->
%%=ReplaceList("a-b", true, "-")=%%
<!-- email 6: expect that the email saves, but the preview fails (HTTP 500) -->
%%=ReplaceList("is true here", "X", true)=%%
<!-- email 7: expect that the save is rejected (HTTP 400) -->
%%=ReplaceList()=%%
<!-- email 8: expect that the save is rejected (HTTP 400) -->
%%=ReplaceList("abc")=%%
<!-- email 9: expect that the save is rejected (HTTP 400) -->
%%=ReplaceList("abc", "z")=%%
Differs from official docs
- Matching ignores case. Not stated in the reference; in Next
ReplaceList("Cat cat CAT", "dog", "cat")givesdog dog dog. Card - Search values apply in sequence. The reference does not say so; in Next
ReplaceList("a", "XY", "a", "X")givesXYYbecause the second value matches text the first one inserted. Card - Numbers and booleans break the render. The reference does not rule them out, but
ReplaceList("a1b", "-", 1)made the Next preview fail with HTTP 500. Card
Availability & differences
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes |
| Marketing Cloud Next | Yes, from API 67.0 |
String calls give the same results on both platforms, including the sequential passes (ReplaceList("a", "XY", "a", "X") gives XYY). Engagement also accepts numbers in every role (ReplaceList(101101, "9", "0") gives 191191) and swallows booleans, while in Next a number or boolean argument makes the email preview fail. Compared 2026-11-23 by rendering the same calls in a Marketing Cloud Next email.
See also
Replace— one search value with its own replacementConcat— the other variadic String function- Differs from official docs (Next)
- Official reference