WLJS LogoWLJS Notebook

Longest

Longest[p] is a pattern object that matches the longest sequence consistent with the pattern p.

Examples

Match longest sequence:

StringCases["aabbbcc", Longest[a ~~ __ ~~ c]]
(* {"aabbbc"} *)

Compare with Shortest:

{StringCases["aabbcc", Longest[a ~~ __ ~~ c]], 
 StringCases["aabbcc", Shortest[a ~~ __ ~~ c]]}
(* {{"aabbc"}, {"abc"}} *)

Please visit the official Wolfram Language Reference for more details.

On this page