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
![](Files/ReplaceRepeated.en/details_1.png)
- 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:
![](Files/ReplaceRepeated.en/I_1.png)
https://wolfram.com/xid/0h2n4bbur6-h4kzb4
![](Files/ReplaceRepeated.en/I_2.png)
https://wolfram.com/xid/0h2n4bbur6-dybzai
![](Files/ReplaceRepeated.en/O_1.png)
ReplaceAll does just a single replacement:
![](Files/ReplaceRepeated.en/I_3.png)
https://wolfram.com/xid/0h2n4bbur6-f7bsez
![](Files/ReplaceRepeated.en/O_2.png)
Remove all occurrences of a head, including nested ones:
![](Files/ReplaceRepeated.en/I_4.png)
https://wolfram.com/xid/0h2n4bbur6-lmujfj
![](Files/ReplaceRepeated.en/O_3.png)
ReplaceAll would only remove the outermost head:
![](Files/ReplaceRepeated.en/I_5.png)
https://wolfram.com/xid/0h2n4bbur6-k9yfsm
![](Files/ReplaceRepeated.en/O_4.png)
Use ReplaceRepeated in operator form:
![](Files/ReplaceRepeated.en/I_6.png)
https://wolfram.com/xid/0h2n4bbur6-836t6x
![](Files/ReplaceRepeated.en/O_5.png)
Scope (3)Survey of the scope of standard use cases
If no rule matches, the input expression is returned:
![](Files/ReplaceRepeated.en/I_7.png)
https://wolfram.com/xid/0h2n4bbur6-qwluyq
![](Files/ReplaceRepeated.en/O_6.png)
Replace occurrences of f with 1 followed by exactly one integer:
![](Files/ReplaceRepeated.en/I_8.png)
https://wolfram.com/xid/0h2n4bbur6-nnbph7
![](Files/ReplaceRepeated.en/O_7.png)
Replace occurrences of f with 1 followed by one or more integers:
![](Files/ReplaceRepeated.en/I_9.png)
https://wolfram.com/xid/0h2n4bbur6-j63gmn
![](Files/ReplaceRepeated.en/O_8.png)
Replace occurrences of f with 1 followed by zero or more integers:
![](Files/ReplaceRepeated.en/I_10.png)
https://wolfram.com/xid/0h2n4bbur6-80fhzf
![](Files/ReplaceRepeated.en/O_9.png)
ReplaceRepeated works inside held expressions:
![](Files/ReplaceRepeated.en/I_11.png)
https://wolfram.com/xid/0h2n4bbur6-icn15m
![](Files/ReplaceRepeated.en/O_10.png)
Do not evaluate the right-hand side of the rule before doing the replacement:
![](Files/ReplaceRepeated.en/I_12.png)
https://wolfram.com/xid/0h2n4bbur6-d4rf13
![](Files/ReplaceRepeated.en/O_11.png)
Evaluate the right-hand side before replacement:
![](Files/ReplaceRepeated.en/I_13.png)
https://wolfram.com/xid/0h2n4bbur6-35kafs
![](Files/ReplaceRepeated.en/O_12.png)
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:
![](Files/ReplaceRepeated.en/I_15.png)
https://wolfram.com/xid/0h2n4bbur6-bm5026
![](Files/ReplaceRepeated.en/O_14.png)
When a list of lists is used for replacement, the result is a list of the same length:
![](Files/ReplaceRepeated.en/I_16.png)
https://wolfram.com/xid/0h2n4bbur6-uie9dq
![](Files/ReplaceRepeated.en/O_15.png)
Evaluation is not forced when replacing into a held expression:
![](Files/ReplaceRepeated.en/I_17.png)
https://wolfram.com/xid/0h2n4bbur6-pfw68a
![](Files/ReplaceRepeated.en/O_16.png)
ReplaceRepeated is effectively a combination of ReplaceAll and FixedPoint:
![](Files/ReplaceRepeated.en/I_18.png)
https://wolfram.com/xid/0h2n4bbur6-cqlakc
![](Files/ReplaceRepeated.en/O_17.png)
![](Files/ReplaceRepeated.en/I_19.png)
https://wolfram.com/xid/0h2n4bbur6-lrfw76
![](Files/ReplaceRepeated.en/O_18.png)
ReplaceRepeated scans multiple times from the top of an expression:
![](Files/ReplaceRepeated.en/I_20.png)
https://wolfram.com/xid/0h2n4bbur6-s30uro
![](Files/ReplaceRepeated.en/I_21.png)
https://wolfram.com/xid/0h2n4bbur6-8x5i4p
![](Files/ReplaceRepeated.en/O_19.png)
ReplaceAll replaces the largest subexpressions it can and then stops:
![](Files/ReplaceRepeated.en/I_22.png)
https://wolfram.com/xid/0h2n4bbur6-04ppi7
![](Files/ReplaceRepeated.en/O_20.png)
![](Files/ReplaceRepeated.en/I_23.png)
https://wolfram.com/xid/0h2n4bbur6-g7tdsa
![](Files/ReplaceRepeated.en/O_21.png)
Replace with level spec All will attempt to replace every subexpression exactly once:
![](Files/ReplaceRepeated.en/I_24.png)
https://wolfram.com/xid/0h2n4bbur6-et2u4c
![](Files/ReplaceRepeated.en/O_22.png)
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: 16-February-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: 16-February-2025
]}