Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Test if a string pattern is within an expression
ResourceFunction["StringWithinQ"][expr,patt] returns True if expr contains a string matching pattern patt. | |
ResourceFunction["StringWithinQ"][patt] represents an operator form of ResourceFunction["StringWithinQ"] that can be applied to an expression. |
IgnoreCase | False | whether to ignore the casing |
"ExactMatch" | False | whether to enforce exact matches (not substring matches) |
Check if a substring is anywhere within an expression:
In[1]:= |
Out[1]= |
Use any valid string pattern for matching:
In[2]:= |
Out[3]= |
Use the operator form of StringWithinQ:
In[4]:= |
Out[4]= |
By default, the casing of the pattern is used in matching. You can override this with the IgnoreCase option:
In[5]:= |
Out[6]= |
In[7]:= |
Out[7]= |
By default, StringWithinQ looks for substring matches:
In[8]:= |
Out[8]= |
You can override this to enforce that patterns match exact strings with the "ExactMatch" option:
In[9]:= |
Out[9]= |
In[10]:= |
Out[10]= |
StringWithinQ is like StringContainsQ, except that it looks deeper inside expressions for a matching string:
In[11]:= |
Out[11]= |
In[12]:= |
Out[12]= |
StringFreeQ does not take level specs like FreeQ does, so StringWithinQ is useful here:
In[13]:= |
Out[13]= |
In[14]:= |
Out[14]= |
Like Cases, keys in associations are not matched:
In[15]:= |
Out[15]= |
In[16]:= |
Out[16]= |
This work is licensed under a Creative Commons Attribution 4.0 International License