ReplaceRepeated
✖
ReplaceRepeated
repeatedly performs replacements until expr no longer changes.
represents an operator form of ReplaceRepeated that can be applied to an expression.
Details and Options

- expr//.rules effectively applies /. repeatedly, until the results it gets no longer change.
- It performs one complete pass over the expression using /., then carries out the next pass.
- You should be very careful to avoid infinite loops when you use the //. operator. The command x//.x->x+1 will, for example, lead to an infinite loop.
- ReplaceRepeated takes the option MaxIterations, which specifies the maximum number of times it will try to apply the rules you give. The default setting is MaxIterations->65536. With MaxIterations->Infinity there is no limit.
- ReplaceRepeated[rules][expr] is equivalent to ReplaceRepeated[expr,rules].
Examples
open allclose allBasic Examples (3)Summary of the most common use cases
Apply rules for the power and product laws for logarithms of real numbers recursively:

https://wolfram.com/xid/0h2n4bbur6-h4kzb4

https://wolfram.com/xid/0h2n4bbur6-dybzai

ReplaceAll does just a single replacement:

https://wolfram.com/xid/0h2n4bbur6-f7bsez

Remove all occurrences of a head, including nested ones:

https://wolfram.com/xid/0h2n4bbur6-lmujfj

ReplaceAll would only remove the outermost head:

https://wolfram.com/xid/0h2n4bbur6-k9yfsm

Use ReplaceRepeated in operator form:

https://wolfram.com/xid/0h2n4bbur6-836t6x

Scope (3)Survey of the scope of standard use cases
If no rule matches, the input expression is returned:

https://wolfram.com/xid/0h2n4bbur6-qwluyq

Replace occurrences of f with 1 followed by exactly one integer:

https://wolfram.com/xid/0h2n4bbur6-nnbph7

Replace occurrences of f with 1 followed by one or more integers:

https://wolfram.com/xid/0h2n4bbur6-j63gmn

Replace occurrences of f with 1 followed by zero or more integers:

https://wolfram.com/xid/0h2n4bbur6-80fhzf

ReplaceRepeated works inside held expressions:

https://wolfram.com/xid/0h2n4bbur6-icn15m

Do not evaluate the right-hand side of the rule before doing the replacement:

https://wolfram.com/xid/0h2n4bbur6-d4rf13

Evaluate the right-hand side before replacement:

https://wolfram.com/xid/0h2n4bbur6-35kafs

Applications (1)Sample problems that can be solved with this function
Properties & Relations (5)Properties of the function, and connections to other functions
An empty list is considered to have no matching rules:

https://wolfram.com/xid/0h2n4bbur6-bm5026

When a list of lists is used for replacement, the result is a list of the same length:

https://wolfram.com/xid/0h2n4bbur6-uie9dq

Evaluation is not forced when replacing into a held expression:

https://wolfram.com/xid/0h2n4bbur6-pfw68a

ReplaceRepeated is effectively a combination of ReplaceAll and FixedPoint:

https://wolfram.com/xid/0h2n4bbur6-cqlakc


https://wolfram.com/xid/0h2n4bbur6-lrfw76

ReplaceRepeated scans multiple times from the top of an expression:

https://wolfram.com/xid/0h2n4bbur6-s30uro

https://wolfram.com/xid/0h2n4bbur6-8x5i4p

ReplaceAll replaces the largest subexpressions it can and then stops:

https://wolfram.com/xid/0h2n4bbur6-04ppi7


https://wolfram.com/xid/0h2n4bbur6-g7tdsa

Replace with level spec All will attempt to replace every subexpression exactly once:

https://wolfram.com/xid/0h2n4bbur6-et2u4c

Wolfram Research (1988), ReplaceRepeated, Wolfram Language function, https://reference.wolfram.com/language/ref/ReplaceRepeated.html (updated 2018).
Text
Wolfram Research (1988), ReplaceRepeated, Wolfram Language function, https://reference.wolfram.com/language/ref/ReplaceRepeated.html (updated 2018).
Wolfram Research (1988), ReplaceRepeated, Wolfram Language function, https://reference.wolfram.com/language/ref/ReplaceRepeated.html (updated 2018).
CMS
Wolfram Language. 1988. "ReplaceRepeated." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2018. https://reference.wolfram.com/language/ref/ReplaceRepeated.html.
Wolfram Language. 1988. "ReplaceRepeated." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2018. https://reference.wolfram.com/language/ref/ReplaceRepeated.html.
APA
Wolfram Language. (1988). ReplaceRepeated. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ReplaceRepeated.html
Wolfram Language. (1988). ReplaceRepeated. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ReplaceRepeated.html
BibTeX
@misc{reference.wolfram_2025_replacerepeated, author="Wolfram Research", title="{ReplaceRepeated}", year="2018", howpublished="\url{https://reference.wolfram.com/language/ref/ReplaceRepeated.html}", note=[Accessed: 06-June-2025
]}
BibLaTeX
@online{reference.wolfram_2025_replacerepeated, organization={Wolfram Research}, title={ReplaceRepeated}, year={2018}, url={https://reference.wolfram.com/language/ref/ReplaceRepeated.html}, note=[Accessed: 06-June-2025
]}