%% Designate ^ and $ Anchors as Line or Text Anchors
% The metacharacters ^ and $ can be used to specify line anchors or text anchors. The behavior that regexpPattern uses is specified by the Anchors option.
% Create txt as a string containing newline characters.

txt = "cat" + newline + "bat" + newline + "rat";

% The regular expression  '^.+?$' matches one or more characters between two anchors. Create a pattern for this regular expression, and specify Anchors as “text” so that the ^ and $ anchors are treated as text anchors. Extract the pattern.

expression = '^.+?$';
pat = regexpPattern(expression,"Anchors","text");
extract(txt,pat)

% Create a new regular expression pattern, but this time specify Anchors as “line” so that the ^ and $ anchors are treated as line anchors. Extract the new pattern.

pat = regexpPattern(expression,"Anchors","line");
extract(txt,pat)

% Copyright 2020 The MathWorks, Inc.