StringCases

StringCases["string",patt]

gives a list of the substrings in "string" that match the string expression patt.

StringCases["string",lhsrhs]

gives a list of the values of rhs corresponding to the substrings that match the string expression lhs.

StringCases["string",p,n]

includes only the first n substrings that match.

StringCases["string",{p1,p2,}]

gives substrings that match any of the pi.

StringCases[{s1,s2,},p]

gives the list of results for each of the si.

StringCases[patt]

represents an operator form of StringCases that can be applied to an expression.

Details and Options

Examples

open allclose all

Basic Examples  (3)

Find the substrings matching a pattern:

In[1]:=
Click for copyable input
Out[1]=

Return only the named wild-card character in each substring:

In[1]:=
Click for copyable input
Out[1]=

Use the operator form of StringCases:

In[1]:=
Click for copyable input
Out[1]=

Scope  (8)

Options  (2)

Applications  (3)

Properties & Relations  (2)

Possible Issues  (1)

Neat Examples  (1)

See Also

TextCases  Cases  TextWords  StringPosition  StringCount  StringReplace  StringContainsQ  StringReplaceList  Characters  StringExpression  RegularExpression  SequenceAlignment  TextSearch

Tutorials

Introduced in 2004
(5.1)
| Updated in 2015
(10.1)