Skip to content

Instantly share code, notes, and snippets.

@sco1
Created April 28, 2016 15:32
Show Gist options
  • Save sco1/df3f59b62914047b09026658df574b99 to your computer and use it in GitHub Desktop.
Save sco1/df3f59b62914047b09026658df574b99 to your computer and use it in GitHub Desktop.
% Generate some dummy data
mystrs = {'hi hello this is robin'; ...
'we are the knights who say ni'; ...
'this is a string'; ...
'knight rider'; ...
'boogie nights'; ...
'boogie knights'; ...
};
querystr = 'knight';
% Generate regular expression...expression based on query string
expression = sprintf('\\<(%s)\\>', querystr);
% Return where matches start in each cell
matchstart = regexp(mystrs, expression, 'start');
% Find first non-empty cell, signifying a match
firstcellwithquerystring = find(~cellfun(@isempty, matchstart), 1, 'first');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment