# Find element in a list matching a pattern (using wildcards)

Somehow, I did not manage to find anything related to that. Suppose, in my Global list of variables, I would like to make a search such that I obtain all the elements in the list which start with func. Trying the naive choice of

Cases[Names["Global*"], func_]


does not work, however I cannot see how to make this work?

You can use PatternTest (?) with StringMatchQ

Cases[Names["Global*"], _?(StringMatchQ["func*"])]


or with StringStartsQ

Cases[Names["Global*"], _?(StringStartsQ["func"]) ]


Note the redundant-looking (..) after ?.

Alternatively, you can use Condition (/;)

Cases[Names["Global*"], x_ /; StringMatchQ[ x, "func*"] ]
Cases[Names["Global*"], x_/;StringStartsQ[ x, "func"] ]


Or, if you are not wedded to Cases and patterns, you could use Select and a predicate, something like

Select[Names["Global$$$$*"], StringStartsQ["func"]]


Why not simply include the pattern in Names?

In[1]:= Names["SystemPlot*"]

Out[1]= {"Plot", "Plot3D", "Plot3Matrix", "PlotDivision", \
"PlotJoined", "PlotLabel", "PlotLabels", "PlotLayout", "PlotLegends", \
"PlotMarkers", "PlotPoints", "PlotRange", "PlotRangeClipping", \
`