# How to use wildcards in SequenceCases

The final task is to revise the question I posed at list rearrangement:

lis = {{1,2,3},{"True",3,4,5},{6,5},{3},{6,4},{"Truex",2,1},{5},{5,6},{7,8,9}}


I want to make a new list consisting of elements of lis that begin with "True" (or "True" followed by any further string characters), and include the next two elements directly following, thus making triplets:

res = {({"True",3,4,5},{6,5},{3}},{{"Truex",2,1},{5},{5,6}}}


Again the task seems to be to get SequenceCases to recognize the pattern that allows it to pick up elements with "True" as well as "True*" Thanks again for ideas.

• SequenceCases[lis, {{_?(StringContainsQ[ToString@#, "True"] &), ___}, _, _}] Commented Sep 22, 2021 at 18:56

SequenceCases[lis, {{_String?(StringMatchQ["True*"]), __}, _, _}]

{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"Truex", 2, 1}, {5}, {5, 6}}}

list =
{{1, 2, 3},
{"True", 3, 4, 5}, {6, 5}, {3}, {6, 4},
{"Truex", 2, 1}, {5}, {5, 6}, {7, 8, 9}};


Using SequencePosition and Take

p = SequencePosition[list, {{x_String /; StringTake[x, 4] == "True", ___}, _, _}]


{{2, 4}, {6, 8}}

Take[list, #] & /@ p


{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"Truex", 2, 1}, {5}, {5, 6}}}