Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • $\begingroup$ I'm on the road, but my first guess is that when q matches X, the replacement results in the same expression. Would that cause it to stop? $\endgroup$ Commented Oct 14, 2024 at 1:57
  • $\begingroup$ @MichaelE2 I see now. Got it thanks! Should I post a solution myself? $\endgroup$ Commented Oct 14, 2024 at 2:04
  • 1
    $\begingroup$ @MichaelE2 I found a workaround, but cannot find no satisfactory answer to my question itself... $\endgroup$ Commented Oct 14, 2024 at 2:36
  • 1
    $\begingroup$ Does this help with finding an explanation: {a, X, c, d, X, b, X} //. {{p___, X, q_, r___} :> (Print[{"q" -> q, #}]; #) &@{p, q, X, r}}? It prints the replacement for each match. lericr has already explained the point in my comment. $\endgroup$ Commented Oct 14, 2024 at 12:52
  • 1
    $\begingroup$ If you make your rule {{p___, X, q : Except[X], r___} :> {p, q, X, r}} or {{p___, X, r__} :> {p, r, X}}, it will work. $\endgroup$ Commented Oct 14, 2024 at 15:13