1

I have an old version of MATLAB which lacks the very useful strsplit function documented here. Is there a way to replicate this functionality?

1 Answers1

6

Yes! Use regexp with the 'split' option as follows. Note that it is necessary to escape characters which have special meaning when calling regexp. regexescape = @(delim) regexprep(delim,'[\^\$()\<[{\\|>.*+\?]','\$0')

One line replacement function for strsplit (courtesy of @AndrasDeak):

mystrsplit = @(str,delim) regexp(str,regexptranslate('escape',delim),'split')

Test cases:

>> strsplit('hi.mom','.')

ans = 

    'hi'    'mom'

>> mystrsplit('hi.mom','.')

ans = 

    'hi'    'mom'