After searching quite thoroughly, I haven't been able to find a good answer... I'm looking to find an option for Replace to stop after it encounters the first rule which applies to some expression. Thanks
Asked
Active
Viewed 76 times
2
ReplacePart[expr, Position[expr, old][[1]] -> new]`
– Bob Hanlon May 05 '17 at 18:51replacement = "A"; {"a", "b", "a", "c"} /. x : "a" :> With[{res = replacement}, replacement = x; res]– Jason B. May 05 '17 at 18:53ReplaceList[exp,rule,1]can do the job. The problem is that the rule is only applied at level 0 of exp. Example : to replace 1 by 2 only one time in {1,1,1}, doReplaceList[{1,1,1},{a___,1,b___}:> {a,2,b},1]. Result :{{2, 1, 1}}– andre314 May 05 '17 at 19:22@mikado, the question indicated was exactly what I was looking for, probably I haven't been clear enough. – Gaby Fleurov May 07 '17 at 09:33