%% Search File for Text
% Read a file and search it for text of interest.
%
% First, read the file fileread.m into a character vector.

filetext = fileread('fileread.m');

%
% Then, define the text to search for.

expr = '[^\n]*fileread[^\n]*';

% Find and return all lines that contain the text 'fileread'.

matches = regexp(filetext,expr,'match');

% Display the first matching line.

disp(matches{1})

% Copyright 2012 The MathWorks, Inc.