Wolfram Research

Function Repository Resource:

StringContainsAll

Source Notebook

Test if a string contains all elements from a list

Contributed by: Jason Biggs

ResourceFunction["StringContainsAll"][string,{patt1,patt2,}]

returns True if string contains each of the patti.

Details and Options

For fastest results, order the patti with the least common pattern first.
ResourceFunction["StringContainsAll"] takes the same options as StringContainsQ.

Examples

Basic Examples

Bring up the opening of the Declaration of Independence:

In[1]:=
string = StringTake[
  ExampleData[{"Text", "DeclarationOfIndependence"}], 400]
Out[1]=
In[2]:=
ResourceFunction[
 "StringContainsAll"][string, {"people", "dissolve", "Laws"}]
Out[2]=

Scope

Find all words containing e, t, l, a and b; then put them in a WordCloud:

In[3]:=
WordCloud@
 Select[DictionaryLookup[], ResourceFunction["StringContainsAll"][{"e", "t", "l", "a", "b"}]]
Out[3]=

Options

String patterns are case sensitive:

In[4]:=
string = StringTake[ExampleData[{"Text", "TheRaven"}], 400]
Out[4]=
In[5]:=
ResourceFunction["StringContainsAll"][string, {"dreary", "december"}]
Out[5]=

Use the option IgnoreCase to match upper- and lower-case letters:

In[6]:=
ResourceFunction["StringContainsAll"][string, {"dreary", "december"}, IgnoreCase -> True]
Out[6]=

Resource History

License Information