%% Parse Text with Newline Characters
% Create a character vector that contains a newline, \n, and parse it using a regular expression. Since regexp returns matchStr as a cell array containing text that has multiple lines, you can take the text out of the cell array to display all lines.

str = sprintf('abc\n de');
expression = '.*';
matchStr = regexp(str,expression,'match');
matchStr{:}

% By default, the dot (.) matches every character, including the newline, and returns a single match that is equivalent to the original character vector.
%
% Exclude newline characters from the match using the 'dotexceptnewline' option. This returns separate matches for each line of text.

matchStrNoNewline = regexp(str,expression,'match','dotexceptnewline')

%
% Find the first or last character of each line using the ^ or $ metacharacters and the 'lineanchors' option.

expression = '.$';
lastInLine = regexp(str,expression,'match','lineanchors')

% Copyright 2012 The MathWorks, Inc.