AQL `SUBSTITUTE()` with several search values skips a match that starts right where the previous replacement ended
Author: the-ShallowCreated Oct 1, 2026Updated Oct 1, 2026
Description
With an array (or object) of search values, SUBSTITUTE() leaves an occurrence unreplaced when it begins at the
position right after a replaced match. A single search value does not have the problem.
Reproduction
RETURN SUBSTITUTE("baaaa", ["ba", "aaa"], ["<1>", "<2>"]) // "<1>aaa", expected "<1><2>"
RETURN SUBSTITUTE("baaaa", ["aaa", "ba"], ["<2>", "<1>"]) // "<1>aaa"
RETURN SUBSTITUTE("abbbb", ["ab", "bbb"], ["<1>", "<2>"]) // "<1>bbb"
RETURN SUBSTITUTE("aaaaaa", "aaa", "x") // "xx" (single value: fine)The documentation says "each occurrence of a value contained in search will be replaced by the corresponding
array element in replace"; aaa occurs at position 2 of baaaa after ba is replaced.
Source: arangodb/arangodb