Skip to content

Instantly share code, notes, and snippets.

@keshavsaharia
Created June 30, 2013 05:46
Show Gist options
  • Save keshavsaharia/5894025 to your computer and use it in GitHub Desktop.
Save keshavsaharia/5894025 to your computer and use it in GitHub Desktop.
A missing function in Mathematica that is essential for many string parsing applications. Inputs a string and a regular expression delimiter, and takes from the string until it matches the delimiter (or takes the entire string if the delimiter is not found).
StringTakeUntil[str_, delim_] :=
If[StringMatchQ[str, delim ~~ ___] || StringLength[str] == 0, "",
StringTake[str, 1] <> StringTakeUntil[StringDrop[str, 1], delim]];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment