Split a string on ' ' and 'ain', treating multiple delimiters as one. Specify multiple delimiters in a cell array of strings.
str = 'The rain in Spain stays mainly in the plain.';
[C,matches] = strsplit(str,{' ','ain'},'CollapseDelimiters',true)
C =
'The' 'r' 'in' 'Sp' 'stays' 'm' 'ly' 'in' 'the' 'pl' '.'
matches =
' ' 'ain ' ' ' 'ain ' ' ' 'ain' ' ' ' ' ' ' 'ain'
Split the same string on whitespace and on 'ain', using regular expressions and treating multiple delimiters separately.
[C,matches] = strsplit(str,{'\s','ain'},'CollapseDelimiters',...
false, 'DelimiterType','RegularExpression')
C =
'The' 'r' '' 'in' 'Sp' '' 'stays' 'm' 'ly' 'in' 'the' 'pl' '.'
matches =
' ' 'ain' ' ' ' ' 'ain' ' ' ' ' 'ain' ' ' ' ' ' ' 'ain'
In this case, strsplit treats the two delimiters separately, so empty strings appear in output Cbetween the consecutively matched delimiters.