Hot answers tagged

13

I am a developer at Wolfram Research and I am trying to share some of the work I have been doing with parsing WL code. I have written a package for parsing WL code and retaining interesting metadata, such as file and line information. I also expose a tokenization function. The paclet is available on the public paclet server: In[1]:= PacletUpdate["AST","...


3

I don't know how extensible this is, but it works for your case, Cases[list, p[args:PatternSequence[___, a, _p, q, ___]] :> SequenceCases[ {args}, {a, p[x_, y_], q} :> {x, y} ], Infinity ] (* {{{1, 2}, {3, 4}, {5, 6}}} *)


2

This also works for your list, but like Jason B, I don't that is will be applicable to your XML problem. Cases[Partition[List @@ list[[1]], 3, 1], {a, u : p[_, _], q} -> u] {p[1, 2], p[3, 4], p[5, 6]}


Only top voted, non community-wiki answers of a minimum length are eligible