%% Prevent Backtracking to Match
% Use possessivePattern so that once the possessive portion of a pattern matches, there is no backtracking. This prevents other patterns in the pattern expression to match.
% Create txt as a string comprised of letter and digit characters. Create nonpossessive as a pattern that matches letters or digits with alphanumericsPattern followed by digits with digitsPattern. On its own, alphanumericsPattern matches the entire string, but it allows backtracking so that digitsPattern is able to match as well.

txt = "abc123";
nonpossessive = alphanumericsPattern + digitsPattern;
successfulMatch = contains(txt,nonpossessive)

% Make alphanumericsPattern possessive. Possessiveness prevents backtracking, so alphanumericsPattern matches the entire string and does not backtrack to allow digitsPattern to match as well. This attribute causes possessive to fail to match txt.

possessive = possessivePattern(alphanumericsPattern) + digitsPattern;
unsuccessfulMatch = contains(txt,possessive)

% Copyright 2020 The MathWorks, Inc.