WLJS LogoWLJS Notebook

ShortestMatch

ShortestMatch[p] is a string pattern object matching the shortest sequence of characters consistent with the string pattern p.

Examples

Match shortest string:

StringCases["aXbXc", "a" ~~ ShortestMatch[__] ~~ "c"]
(* {"aXbXc"} *)

Compare with greedy match:

StringCases["<a><b>", "<" ~~ ShortestMatch[__] ~~ ">"]
(* {"<a>", "<b>"} *)

Please visit the official Wolfram Language Reference for more details.

On this page