extracts the n^(th) block of characters in string, where blocks of characters are defined as delimited by whitespace.


extracts blocks at several positions in string.


takes blocks to be delimited by separators that match sep.


extracts blocks at positions posi, delimiting with whitespace for the lowest level, newlines for the next level, and a successively increasing number of newlines thereafter.


gives a nested list of blocks, with the sepi used as separators for successive levels.


  • The position specifications for blocks can have any of the following forms:
  • nn^(th) block
    -nn^(th) block counting from the end
    {n1,n2,}collection of blocks
    n1;;n2n1^(th) through n2^(th) block
    Allall blocks
  • The separator sep can be a literal string or a string pattern.


open allclose all

Basic Examples  (3)

Extract the second word from a string:

Extract a sequence of words:

Use -- as a word separator:

Scope  (4)

Extract the last word from a string:

Extract the first and third words:

Extract all whitespace-delimited tokens:

Extract the English words from the text:

Take the first word from each line:

Take the first word from the third line:

Take every word from the third line:

Elements not present in a group yield Missing[]:

Applications  (1)

Extract the first column from a string in CSV (comma-separated values) format:

Extract all columns:

Extract only the first row:

Properties & Relations  (4)

StringExtract["string",pattAll] is equivalent to StringSplit["string",patt]:

StringExtract["string",{pos1,pos2,}] is equivalent to Part[StringSplit["string"],{pos1,pos2,}]:

StringExtract["string",,pos-3,pos-2,pos-1] is equivalent to StringExtract["string",,"\n\n"pos-3,"\n"pos-2,Whitespacepos-1]:

StringExtract can be used on the output of StringRiffle:

Wolfram Research (2015), StringExtract, Wolfram Language function,


Wolfram Research (2015), StringExtract, Wolfram Language function,


Wolfram Language. 2015. "StringExtract." Wolfram Language & System Documentation Center. Wolfram Research.


Wolfram Language. (2015). StringExtract. Wolfram Language & System Documentation Center. Retrieved from


@misc{reference.wolfram_2024_stringextract, author="Wolfram Research", title="{StringExtract}", year="2015", howpublished="\url{}", note=[Accessed: 13-June-2024 ]}


@online{reference.wolfram_2024_stringextract, organization={Wolfram Research}, title={StringExtract}, year={2015}, url={}, note=[Accessed: 13-June-2024 ]}