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.

TextCases[text,formprop]

gives the specified property for each case of form.

TextCases[text,formprop,n]

gives the specified property for the first n cases.

Details and Options

  • In TextCases[text,form], text can be a string, a file with plain text, a ContentObject expression or a list of these text objects.
  • Possible choices for the property prop 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
    {prop1,prop2,}a list of property 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
    "Person"notable person
    "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

Examples

open allclose all

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]=

Scope  (9)

Applications  (2)

Properties & Relations  (1)

Neat Examples  (1)

See Also

TextPosition  TextSentences  TextWords  Containing  StringCases  Interpreter  FindTextualAnswer

Introduced in 2015
(10.2)
| Updated in 2018
(11.3)