Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Split a string after each substring matching a string pattern
| ResourceFunction["StringSplitAfter"]["string"] splits "string" into a list of substrings after each whitespace. | |
| ResourceFunction["StringSplitAfter"]["string",patt] splits "string" into substrings after delimiters matching the string expression patt. | |
| ResourceFunction["StringSplitAfter"]["string",{p1,p2,…}] splits "string" after any of the pi. | |
| ResourceFunction["StringSplitAfter"]["string",patt→val] replaces each delimiter matching patt with val. | |
| ResourceFunction["StringSplitAfter"]["string",{p1→v1,…}] replaces each delimiter matching pi with vi. | |
| ResourceFunction["StringSplitAfter"][{s1,s2,…},p] gives the list of results for each of the si. | 
Split a string after each whitespace (without removing the whitespace):
| In[1]:= | ![ResourceFunction["StringSplitAfter"]["a bbb  cccc aa   d"]](https://www.wolframcloud.com/obj/resourcesystem/images/619/619132be-58a4-41ad-9ad9-37a70c5566c3/6a6697135e6846d3.png) | 
| Out[1]= |  | 
Split a string after every "--" (without removing the "--"):
| In[2]:= | ![ResourceFunction["StringSplitAfter"]["a--bbb---ccc--dddd", "--"]](https://www.wolframcloud.com/obj/resourcesystem/images/619/619132be-58a4-41ad-9ad9-37a70c5566c3/099ea621c1af12d6.png) | 
| Out[2]= |  | 
Split after every run of spaces:
| In[3]:= | ![ResourceFunction["StringSplitAfter"]["the cat in the hat"]](https://www.wolframcloud.com/obj/resourcesystem/images/619/619132be-58a4-41ad-9ad9-37a70c5566c3/565b8a963f446b14.png) | 
| Out[3]= |  | 
Use string patterns:
| In[4]:= | ![ResourceFunction["StringSplitAfter"]["192.168.0.1", "."]](https://www.wolframcloud.com/obj/resourcesystem/images/619/619132be-58a4-41ad-9ad9-37a70c5566c3/173d085980c60bbc.png) | 
| Out[4]= |  | 
| In[5]:= | ![ResourceFunction["StringSplitAfter"]["123  2.3  4  6", WhitespaceCharacter ..]](https://www.wolframcloud.com/obj/resourcesystem/images/619/619132be-58a4-41ad-9ad9-37a70c5566c3/475534ab2843914b.png) | 
| Out[5]= |  | 
| In[6]:= | ![ResourceFunction["StringSplitAfter"]["11a22b3", _?LetterQ]](https://www.wolframcloud.com/obj/resourcesystem/images/619/619132be-58a4-41ad-9ad9-37a70c5566c3/7ad16214bbc946eb.png) | 
| Out[6]= |  | 
Regular expressions:
| In[7]:= | ![ResourceFunction[
 "StringSplitAfter"]["A tree, an apple, four pears. And more: two sacks", RegularExpression["\\W+"]]](https://www.wolframcloud.com/obj/resourcesystem/images/619/619132be-58a4-41ad-9ad9-37a70c5566c3/5a8d7138a881bb59.png) | 
| Out[7]= |  | 
Mixed regular expressions and string patterns:
| In[8]:= | ![ResourceFunction[
 "StringSplitAfter"]["primes: 2 two 3 three 5 five ...", Whitespace ~~ RegularExpression["\\d"] ~~ Whitespace]](https://www.wolframcloud.com/obj/resourcesystem/images/619/619132be-58a4-41ad-9ad9-37a70c5566c3/566db17755ed4da6.png) | 
| Out[8]= |  | 
Split into substrings after either delimiter:
| In[9]:= | ![ResourceFunction["StringSplitAfter"]["a-b:c-d:e-f-g", {":", "-"}]](https://www.wolframcloud.com/obj/resourcesystem/images/619/619132be-58a4-41ad-9ad9-37a70c5566c3/31dcc51b84c70111.png) | 
| Out[9]= |  | 
| In[10]:= | ![ResourceFunction["StringSplitAfter"]["a-b:c-d:e-f-g", ":" | "-"]](https://www.wolframcloud.com/obj/resourcesystem/images/619/619132be-58a4-41ad-9ad9-37a70c5566c3/61c5da3853d93913.png) | 
| Out[10]= |  | 
Replace a delimiter:
| In[11]:= | ![ResourceFunction["StringSplitAfter"]["a b::c d::e f g", "::" -> "--"]](https://www.wolframcloud.com/obj/resourcesystem/images/619/619132be-58a4-41ad-9ad9-37a70c5566c3/57624487f2ef28ad.png) | 
| Out[11]= |  | 
SplitStringAfter automatically threads over lists of strings:
| In[12]:= | ![ResourceFunction[
 "StringSplitAfter"][{"a:b:c:d", "listable:element"}, ":"]](https://www.wolframcloud.com/obj/resourcesystem/images/619/619132be-58a4-41ad-9ad9-37a70c5566c3/6d6582826e183dd8.png) | 
| Out[12]= |  | 
Split a string after every "c", including uppercase letters:
| In[13]:= | ![ResourceFunction["StringSplitAfter"]["cat Cat hat CAT", "c", IgnoreCase -> True]](https://www.wolframcloud.com/obj/resourcesystem/images/619/619132be-58a4-41ad-9ad9-37a70c5566c3/5efa7abda0c2c23c.png) | 
| Out[13]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License