MATLAB: Find prefix and postfix in a string

cell arraypostfixprefixstring

Hi! I have a cell array (106×1) of strings, I want to find a prefix in every string and, after find the postfix, count the number of different items. Example
'0(012)(02)3(26)'
'(03)2(12)04)'
'(45)(02)(35)21'
'46(15)212'
For the prefix '01' the postfix are:
'(_2)(02)3(26)'
'(_2)04'
'3'
now i want to count the items more frequent: 0, 2, _2
Can you help me? Thanks

Best Answer

You can't have a regex that returns the before and after of a sequence of characters without that sequence of characters, but you can do your search and replace in two steps
in = {'0(012)(02)3(26)'
'(03)2(012)04)'
'(45)(02)(35)21'
'46(15)212'};
matches = regexp(in, '\(?01.*', 'match', 'once');
out = regexprep(matches, '01', '_') %note that you could simply use strrep
As for your question about frequency, I still have no idea what constitute an item or element.