5

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:

Roman
  • 47,322
  • 2
  • 55
  • 121

0 Answers0