search for substring in cell array of strings
1 view (last 30 days)
Show older comments
Hello,
I have this cell array of strings:
A = { 'This is how we do the shuffle', 'All night long there', 'In the club'};
I want to return the cell index where there is no 'the' in the cell array. I am using the following code:
str = 'the';
the _str = sprintf('\\<%s\\>',str);
index = strfind(A,the_str);
index_nothe = find(cellfun(@isempty,index));
however, I get an empty array for index. I put the '\\<%s\\>' to search for only the word 'the'.
I would like to return [2] for index, as that is the only cell that does not contain 'the'.
Can you tell me where I am going wrong?
Thanks.
0 Comments
Answers (1)
Azzi Abdelmalek
on 3 Jun 2015
Edited: Azzi Abdelmalek
on 3 Jun 2015
A = { 'This is how we do the shuffle', 'All night long there', 'In the club'}
idx=find(cellfun(@isempty,regexp(A,'the(\s)+','match')))
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!