Wolfram Language & System 11.0 (2016)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.View current documentation (Version 11.2)

TextCases

TextCases["text",form]
gives a list of all cases of form that occur in text.

TextCases["text",form,n]
gives the first n cases that occur.

Details and OptionsDetails and Options

  • By default, TextCases["text",form] returns all substrings of text that match the specified form.
  • In TextCases["text",form->spec], spec defines what should be returned for each match.
  • Possible choices for spec are:
  • "String"the substring of text matched (default)
    "Position"the start and end position of the substring matched
    "Type"the type of object matched (e.g. "Word" or "Country")
    "Interpretation"the standard interpretation of the object matched
    {spec1,spec2,}a list of several specifications
  • Structural choices for form include:
  • "Word"word-like unit (usually delimited by whitespace)
    "Sentence"sentence-like unit (usually delimited by .)
    "Paragraph"paragraph-like unit (delimited by multiple newlines etc.)
    "Quotation"quotation delimited by quotation marks
    "Line"substring delimited by newline
    "Punctuation"punctuation mark (e.g. "?", "!!!", etc.)
    "NonText"characters not in ordinary letter-like text
  • Grammatical choices for form include:
  • "Noun","Verb",specified part of speech
    "ProperNoun"proper noun
    "Emoticon"textual emoticon
  • Formatting-based choices for form include:
  • "URL"correctly formatted URL
    "EmailAddress"correctly formatted email address
    "TwitterHandle"correctly formatted Twitter handle
    "PhoneNumber"international phone numbers
  • Semantic choices for form include:
  • "Number"number in standard format
    "Quantity"quantity with units
    "CurrencyAmount"currency with denomination
    "Country"country or country designation
    "City"city
    "Color"color specification or name
    "English","Chinese",sentences written in the specified language
    "Profanity"paragraphs that contain profanity
    "PositiveSentiment",paragraphs with positive, negative, or neutral sentiment
    Entity["type",name]strings corresponding to a particular entity
  • Combination choices for form include:
  • form1|form2|form matching any of the formi
    Containing[outer,inner]forms of type outer containing ones of type inner
  • The following options for TextCases can be given:
  • PerformanceGoalAutomaticwhat aspects of performance to optimize
  • Possible settings for PerformanceGoal include "Speed" and "Quality".
  • TextCases[ContentObject[]] gives cases from the plain-text contents of the ContentObject.

ExamplesExamplesopen allclose all

Basic Examples  (5)Basic Examples  (5)

Find the words in a sentence:

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

Find the sentences in a string:

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

Find currency amounts:

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

Find cities in text:

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

Find instances of colors in a ContentObject:

In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=
Introduced in 2015
(10.2)