StringSplit["string"]
splits "string" into a list of substrings separated by whitespace.
StringSplit["string",patt]
splits into substrings separated by delimiters matching the string expression patt.
StringSplit["string",{p1,p2,…}]
splits at any of the pi.
StringSplit["string",pattval]
inserts val at the position of each delimiter.
StringSplit["string",{p1v1,…}]
inserts vi at the position of each delimiter pi.
StringSplit["string",patt,n]
splits into at most n substrings.
StringSplit[{s1,s2,…},p]
gives the list of results for each of the si.
StringSplit
StringSplit["string"]
splits "string" into a list of substrings separated by whitespace.
StringSplit["string",patt]
splits into substrings separated by delimiters matching the string expression patt.
StringSplit["string",{p1,p2,…}]
splits at any of the pi.
StringSplit["string",pattval]
inserts val at the position of each delimiter.
StringSplit["string",{p1v1,…}]
inserts vi at the position of each delimiter pi.
StringSplit["string",patt,n]
splits into at most n substrings.
StringSplit[{s1,s2,…},p]
gives the list of results for each of the si.
Details and Options
- StringSplit[s] does not return the whitespace characters that delimit the substrings it returns.
- Whitespace includes any number of spaces, tabs, and newlines.
- The string expression patt can contain any of the objects specified in the notes for StringExpression.
- StringSplit[s] is equivalent to StringSplit[s,Whitespace].
- If s contains two adjacent delimiters, StringSplit considers there to be a zero‐length substring "" between them.
- StringSplit[s,patt] by default gives the list of substrings of s that occur between delimiters defined by patt; it does not include the delimiters themselves.
- StringSplit[s,patt->val] includes val at the position of each delimiter.
- StringSplit[s,patt:>val] evaluates val only when the pattern is found.
- StringSplit["string",{p1->v1,…,pa,…}] includes v1 at the position of delimiters matching p1, but omits delimiters matching pa.
- By default, StringSplit[s,patt] drops zero‐length substrings associated with delimiters that appear at the beginning or end of s.
- StringSplit[s,patt,All] returns all substrings, including zero‐length ones at the beginning or end.
- StringSplit takes the following option:
-
IgnoreCase False whether to turn off case-sensitive matching - Setting the option IgnoreCase->True makes StringSplit treat lowercase and uppercase letters as equivalent.
- StringSplit["string",RegularExpression["regex"]] splits at delimiters matching the specified regular expression.
- StringSplit[BioSequence["type","seq"],patt,…] will split the string "seq" by patt yielding a list of biomolecular sequences. In this case, degenerate letters in patt are interpreted as wildcard patterns based on the type of biomolecular sequence. Use Verbatim["patt"] to match degenerate letters literally.
- The documentation for BioSequence lists the degenerate letters supported by each type of biomolecular sequence.
Examples
open all close allBasic Examples (2)
Scope (11)
StringSplit["the cat in the hat"]StringSplit["192.168.0.1", "."]StringSplit["123 2.3 4 6", WhitespaceCharacter..]StringSplit["11a22b3", _ ? LetterQ]StringSplit["A tree, an apple, four pears. And more: two sacks", RegularExpression["\\W+"]]Mixed regular expressions and string patterns:
StringSplit["primes: 2 two 3 three 5 five ...", Whitespace ~~ RegularExpression["\\d"] ~~ Whitespace]Split into substrings separated by either delimiter:
StringSplit["a-b:c-d:e-f-g", {":", "-"}]StringSplit["a-b:c-d:e-f-g", ":" | "-"]Insert a value at the position of a delimiter:
StringSplit["a b::c d::e f g", "::" -> "--"]Include the delimiters in the output:
StringSplit["a--b c--d e", x : "--" :> x]StringSplit automatically threads over lists of strings:
StringSplit[{"a:b:c:d", "listable:element"}, ":"]Split a DNA sequence by a particular substring:
StringSplit[BioSequence["DNA", "GATGGCAAGGCAG"], "GGC"]Use a wildcard in the pattern to split the biomolecular sequence:
StringSplit[BioSequence["DNA", "GATGGCAAGGNAG"], "GGN"]The "N" is a degenerate letter only in biomolecular sequences:
StringSplit["GATGGCAAGGNAG", "GGN"]Split only on literal degenerate letters using Verbatim:
StringSplit[BioSequence["DNA", "GATGGCAAGGNAG"], "GG" ~~ Verbatim["N"]]Generalizations & Extensions (1)
Options (1)
Applications (4)
Make a nested array by applying StringSplit twice:
StringSplit[StringSplit["11:12:13//21:22:23//31:32:33", "//"], ":"]SeedRandom[1234];
dna = StringJoin[RandomChoice[{"a", "c", "g", "t"}, 500]];Sequences with adenine symmetrically placed:
StringSplit[dna, x : ("a" ~~ y_ ~~ _ ~~ y_ ~~ "a") :> Style[x, FontColor -> Red]] //RowText analysis with some right and left context:
text = Import["ExampleData/USConstitution.txt"];Use StringSplit to find all occurrences of the word "power":
a = StringSplit[text, "power", 10];Compute part of the left and right contexts in which each word occurs:
Apply[Row[{"…", StringTake[#1, -Min[15, StringLength[#1]]], Style["power", Blue], StringTake[#2, Min[15, StringLength[#2]]], "…"}]&, Partition[a, 2, 1], {1}]//ColumnList extensions of files in a directory and its subdirectories:
SetDirectory[$InstallationDirectory];files = FileNames["@.*", {"*"}, Infinity];Union[Last[StringSplit[#, "."]] & /@ files]Properties & Relations (4)
Splitting at whitespace is equivalent to cases of non-whitespace sequences:
StringSplit["a bbb cccc aa d"]StringCases["a bbb cccc aa d", Except[WhitespaceCharacter]..]StringSplit with a rule is equivalent to StringReplace:
StringJoin[StringSplit["ab::c::d::ef", "::" -> "X"]]StringReplace["ab::c::d::ef", "::" -> "X"]A null delimiter splits at every character:
StringSplit["abcdefg", ""]Characters["abcdefg"]Using StringSplit on a comma-separated values string:
StringSplit[StringSplit["123, 2.3, 45.
345, 1.4, 450", "
"], ","]//ToExpressionIn many cases Import and ImportString provide direct functionality:
ImportString["123, 2.3, 45.
345, 1.4, 450", "CSV"]Possible Issues (1)
StringSplit by default splits only at whitespace:
StringSplit["This is a sentence--which goes on."]StringSplit["This is a sentence, which goes on.", Except[WordCharacter]..]Another way to split into words:
StringCases["This is a sentence, which goes on.", WordCharacter..]See Also
SequenceSplit Split StringTrim StringCases FileNameSplit StringExtract StringPartition
Function Repository: StringSplitBefore StringSplitAfter
Tech Notes
History
Introduced in 2004 (5.1) | Updated in 2020 (12.2)
Text
Wolfram Research (2004), StringSplit, Wolfram Language function, https://reference.wolfram.com/language/ref/StringSplit.html (updated 2020).
CMS
Wolfram Language. 2004. "StringSplit." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/StringSplit.html.
APA
Wolfram Language. (2004). StringSplit. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/StringSplit.html
BibTeX
@misc{reference.wolfram_2026_stringsplit, author="Wolfram Research", title="{StringSplit}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/StringSplit.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_stringsplit, organization={Wolfram Research}, title={StringSplit}, year={2020}, url={https://reference.wolfram.com/language/ref/StringSplit.html}, note=[Accessed: 12-June-2026]}