This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

StringCases

StringCases
gives a list of the substrings in that match the string expression patt.
StringCases
gives a list of the values of rhs corresponding to the substrings that match the string expression lhs.
StringCases
includes only the first n substrings that match.
StringCases
gives substrings that match any of the .
StringCases
gives the list of results for each of the .
  • String expressions can contain any of the objects specified in the notes for StringExpression.
  • With Overlaps->All, multiple substrings that match the same string expression are all included. With Overlaps->True, only the first such matching substring at a given position is included.
  • StringCases evaluates rhs only when the pattern is found.
Find the substrings matching a pattern:
Return only the named wild-card character in each substring:
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 string patterns:
Use a regular expression:
Use pattern matching for dates:
Mixed regular expressions and string patterns:
Rules to extract values corresponding to matching substrings:
Include only the two first strings that match:
Occurrences in either substring:
StringCases automatically threads over lists of strings:
Find all substrings "cat", including use of uppercase letters:
Find all runs of two or more letters starting with the letter "a":
Allow overlaps between the substrings:
Allow multiple substrings to start at the same character as well:
Extract phone numbers from a text:
Find the sequence of section numbers in the U.S. Constitution:
Find the numbers of amendments to the Constitution:
Primes whose digits are all consecutive:
StringCount gives the number of matching substrings:
The length of matching substrings:
Use StringPosition to get the position of matching substrings:
Check:
Use rather than if the right-hand side of a rule contains string operations:
Using in such cases leads to immediate evaluation and possible error messages:
Find the sequence of words in the U.S. Constitution:
Total number of words:
Number of distinct words:
Logarithmic frequency distribution of words:
Ten most common words:
New in 5.1