Apologies if this has an answer somewhere but I can't find it.

From the examples for SequencePosition we are shown that

SequencePosition[{a, b, b, a, b, b, b}, {Repeated[b]}]

{{2, 3}, {3, 3}, {5, 7}, {6, 7}, {7, 7}}

If I change the pattern:

SequencePosition[{a, b, b, a, b, b, b}, {b, ___, b}]

{{2, 7}, {3, 7}, {5, 7}, {6, 7}}

Now I want to match the shortest lengths of blank null sequences, so I guess my desired outputs is {{2,3}, {3,5}, {5,6}, {6,7}. But Shortest doesn't seem to change anything:

SequencePosition[{a, b, b, a, b, b, b}, {b, Shortest[___], b}]

{{2, 7}, {3, 7}, {5, 7}, {6, 7}}

Where am I going wrong?

  • $\begingroup$ Try SequencePosition[{a, b, b, a, b, b, b}, {b, Except[b] ..., b}]. $\endgroup$
    – Kuba
    May 10, 2016 at 11:10
  • $\begingroup$ I suppose this is the same issue, yet I'm not sure: mathematica.stackexchange.com/q/72283/5478 $\endgroup$
    – Kuba
    May 10, 2016 at 11:11
  • $\begingroup$ That's strange: looks like Shortest is simply ignored! The expected behavior should be as in SequencePosition[{a, b, c, d}, {Shortest[__]}] and SequencePosition[{a, b, c, d}, {__}]. I suspect a bug. $\endgroup$ May 10, 2016 at 12:22
  • $\begingroup$ @Kuba That thread is about pattern matching in strings (implemented via PCRE), this question is about matching of usual patterns. So these questions are completely independent. $\endgroup$ May 10, 2016 at 12:27
  • $\begingroup$ @AlexeyPopkov not entirely. There are no RegExps on OPs side there. They will be after translation from MMA patterns, so it is about Shortest too. Yet I won't insist, I'm not an expert in pattern matching. $\endgroup$
    – Kuba
    May 10, 2016 at 12:36


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.