MATLAB Answers

0

Extracing the part of the string from cell array

Latest activity Commented on by Paolo
on 25 Jun 2018
I have a cell array a = {'abc__first__element' ; 'def__second__element'; ghi__third__element'}
I want to extract the string after first '__'
My final answer should be a = {'first__element'; 'second__element'; 'third__element'}
How can do this?
Thanks a lot

  0 Comments

Sign in to comment.

1 Answer

Answer by Paolo
on 25 Jun 2018
 Accepted Answer

regexp(a,'(?<=__)(.*)','match')

  2 Comments

+1 nice and simple. To avoided nested cell arrays in the output use the 'once' option:
regexp(a,'(?<=__)(.*)','match','once')
Good point! Would +1 your comment if that was a thing.

Sign in to comment.