%% Split String and Return Delimiters
% Create a string. Starting in R2017a, you can create strings using double quotes.

str = "bacon, lettuce, and tomato"

%
% Split str on delimiters. Return the results of the split in a string array, and the delimiters in a second string array. When there is no text between consecutive delimiters, split returns an empty string.

[newStr,match] = split(str,["and",","," "])

%
% Join newStr and match back together with the join function.

originalStr = join(newStr,match)

% Copyright 2012-2020 The MathWorks, Inc.