%% Match Boundaries Except Those That Precede Specified Pattern
% Use the ~ operator to negate lookAheadBoundary.
% Create a pattern that matches digits except for those directly precede "b" or "2".

txt = "abc 123";
pat = ~lookAheadBoundary("b"|"2");

% Use replace to insert "|" characters at the negated boundaries.

replace(txt,pat,"|")

% Copyright 2020 The MathWorks, Inc.