Why does Shortest
not work in a SequencePosition
call? The following two commands return the same answer:
SequencePosition[{1, 2, 3, 4, 5}, {a_, ___, b_}]
(* {{1, 5}, {2, 5}, {3, 5}, {4, 5}} *)
SequencePosition[{1, 2, 3, 4, 5}, {a_, Shortest[___], b_}]
(* {{1, 5}, {2, 5}, {3, 5}, {4, 5}} *)
I would prefer it if the second one returned
(* {{1, 2}, {2, 3}, {3, 4}, {4, 5}} *)
Do you know how to achieve this behavior?
Notice that the closely related StringPosition
works as expected:
StringPosition["12345", a_ ~~ ___ ~~ b_]
(* {{1, 5}, {2, 5}, {3, 5}, {4, 5}} *)
StringPosition["12345", a_ ~~ Shortest[___] ~~ b_]
(* {{1, 2}, {2, 3}, {3, 4}, {4, 5}} *)
Related:
StringPosition
doesn't share the problem - it is based on a common (textual) regular expression matcher (was it PCRE?), while the pattern matcher in Mathematica is their own. $\endgroup$