%% Match as Few Instances of Pattern as Possible
% Use asFewOfPattern to match as few individual letters as possible between two instances of "b".
% Create txt as a string. Create a pattern, pat, that matches as few of the letters "a" or "b" as possible between two instances of the character "b".

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

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

replace(txt,pat,"*")

% Copyright 2020 The MathWorks, Inc.