Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Split a string before each substring matching a string pattern
ResourceFunction["StringSplitBefore"]["string"] splits "string" into a list of substrings before each whitespace. | |
ResourceFunction["StringSplitBefore"]["string",patt] splits "string" into substrings before delimiters matching the string expression patt. | |
ResourceFunction["StringSplitBefore"]["string",{p1,p2,…}] splits "string" before any of the pi. | |
ResourceFunction["StringSplitBefore"]["string",patt→val] replaces each delimiter matching patt with val. | |
ResourceFunction["StringSplitBefore"]["string",{p1→v1,…}] replaces each delimiter matching pi with vi. | |
ResourceFunction["StringSplitBefore"][{s1,s2,…},p] gives the list of results for each of the si. |
Split a string before each whitespace (without removing the whitespace):
In[1]:= |
Out[1]= |
Split a string before every "--" (without removing the "--"):
In[2]:= |
Out[2]= |
Split before every run of spaces:
In[3]:= |
Out[3]= |
Use string patterns:
In[4]:= |
Out[4]= |
In[5]:= |
Out[5]= |
In[6]:= |
Out[6]= |
Regular expressions:
In[7]:= |
Out[7]= |
Mix regular expressions and string patterns:
In[8]:= |
Out[8]= |
Split into substrings before either delimiter:
In[9]:= |
Out[9]= |
In[10]:= |
Out[10]= |
Replace a delimiter:
In[11]:= |
Out[11]= |
StringSplitBefore automatically threads over lists of strings:
In[12]:= |
Out[12]= |
Split a string before every "c", including uppercase letters:
In[13]:= |
Out[13]= |
This work is licensed under a Creative Commons Attribution 4.0 International License