WLJS LogoWLJS Notebook

Shortest

Shortest[p] is a pattern object that matches the shortest sequence consistent with the pattern p.

Examples

Match shortest sequence:

ReplaceList[{a, b, c, d}, {Shortest[x__], y__} -> {{x}, {y}}]
(* {{{a}, {b, c, d}}} *)

Compare with longest match:

Cases[{{a, b}, {a, b, c}, {a}}, {Shortest[__]}]
(* {{a}} *)

Please visit the official Wolfram Language Reference for more details.

On this page