2

Here is what I want to do:

I have a list of strings for example

s={"red carpet","red box","black carpet","black box"}

I want to use something like

Select[s, StringMatchQ[#, "red"] &] (*to get an output*)
{"red carpet","red box"}

thx in advance for your help

Kuba
  • 136,707
  • 13
  • 279
  • 740
kevin
  • 97
  • 3

1 Answers1

1

You were looking for StringFreeQ I think:

Select[s, ! StringFreeQ[#, "red"] &]

Another way, StringCases with a regular expression:

StringCases[s, RegularExpression[".*red.*"]] // Flatten
BoLe
  • 5,819
  • 15
  • 33