ReplaceList[expr,rules]
attempts to transform the entire expression expr by applying a rule or list of rules in all possible ways, and returns a list of the results obtained.
ReplaceList[expr,rules,n]
gives a list of at most n results.
ReplaceList[rules]
is an operator form of ReplaceList that can be applied to an expression.
ReplaceList
ReplaceList[expr,rules]
attempts to transform the entire expression expr by applying a rule or list of rules in all possible ways, and returns a list of the results obtained.
ReplaceList[expr,rules,n]
gives a list of at most n results.
ReplaceList[rules]
is an operator form of ReplaceList that can be applied to an expression.
Details
- When no transformation is possible, ReplaceList returns {}.
- ReplaceList[rules][expr] is equivalent to ReplaceList[expr,rules].
Examples
open all close allBasic Examples (2)
Give the results of all possible replacements:
ReplaceList[{a, b, c, d, e, f}, {x__, y__} -> {{x}, {y}}]Give only the first replacement that applies:
Replace[{a, b, c, d, e, f}, {x__, y__} -> {{x}, {y}}]Use ReplaceList in operator form:
ReplaceList[{x__, y__} -> {{x}, {y}}][{a, b, c, d}]Scope (2)
Applications (3)
Generate all consecutive nonempty sublists:
ReplaceList[{a, b, c, d}, {___, x__, ___} -> {x}]Find all elements that appear twice:
ReplaceList[{a, b, b, b, c, c, a}, {___, x_, x_, ___} -> x]Find all sublists flanked by the same element:
ReplaceList[{a, b, c, a, d, b, d}, {___, x_, y__, x_, ___} -> {x, {y}}]Properties & Relations (1)
ReplaceList gives a list of results using all possible matches:
ReplaceList[a + b + c, x_ + y_ :> {x, y}]Replace gives the first, canonical match:
Replace[a + b + c, x_ + y_ :> {x, y}]See Also
Replace ReplaceAll StringReplaceList Cases Trace Position Split
Function Repository: MultiReplace
Related Guides
History
Introduced in 1996 (3.0) | Updated in 2018 (11.3)
Text
Wolfram Research (1996), ReplaceList, Wolfram Language function, https://reference.wolfram.com/language/ref/ReplaceList.html (updated 2018).
CMS
Wolfram Language. 1996. "ReplaceList." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2018. https://reference.wolfram.com/language/ref/ReplaceList.html.
APA
Wolfram Language. (1996). ReplaceList. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ReplaceList.html
BibTeX
@misc{reference.wolfram_2026_replacelist, author="Wolfram Research", title="{ReplaceList}", year="2018", howpublished="\url{https://reference.wolfram.com/language/ref/ReplaceList.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_replacelist, organization={Wolfram Research}, title={ReplaceList}, year={2018}, url={https://reference.wolfram.com/language/ref/ReplaceList.html}, note=[Accessed: 12-June-2026]}