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

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

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

replace(txt,pat,"*")

% Copyright 2020 The MathWorks, Inc.