%% Specify Minimum and Maximum Instances of Pattern to Match
% Use asFewOfPattern to match as few individual letters as possible between two instances of "b", but require at least three and no more than four letters.
% Create txt as a string. Create a pattern, pat, that will match as few of the letters "a" or "b" as possible between two instances of the character "b", but specify that there must be a minimum of three and no more than four letters.

txt = "bb bab babab babaaabab";
pat = "b" + asFewOfPattern("a"|"b",3,4) + "b";

% Use replace to replace text matched by pat with the character "*".

replace(txt,pat,"*")

% Copyright 2020 The MathWorks, Inc.