This question already has an answer here:

I am trying to match expressions that are the sum of two or more objects with a specific head. However I can not get this work properly.

For example

obj[a]+obj[b] /. Plus[A:Repeated[_obj,{2,Infinity}] :> Hold[A] 



instead of


as desired.

Somewhat confusingly allowing single repeats

obj[a]+obj[b] /. Plus[A:Repeated[_obj,{1,Infinity}] :> Hold[A]

does return


as expected. Also using a different overall head instead of "Plus" for example "List" also works

List[obj[a],obj[b]] /. List[A:Repeated[_obj,{2,Infinity}] :> Hold[A] 



Does anybody have an idea what is going on here (and how to achieve what I was trying in the first place)?


marked as duplicate by Mr.Wizard Apr 14 '16 at 11:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ Plus on the left-hand-side of the rule evaluates, which changes your pattern. Try obj[a] + obj[b] /. Verbatim[Plus][A : Repeated[_obj, {2, Infinity}]] :> Hold[A] instead. This question is a duplicate and I shall mark it as such in a minute. $\endgroup$ – Mr.Wizard Apr 14 '16 at 11:22
  • $\begingroup$ If anyone has a suggestion for a better duplicate please comment or flag. $\endgroup$ – Mr.Wizard Apr 14 '16 at 11:23