%% Replace Text Between Specified Patterns
% Since R2020b
% Create abbreviations like "i18n" for "internationalization". To do this, replace the text between the first and last letters of a word with the number of letters.
% First, create a string array.

str = ["globalization";
       "internationalization";
       "localization"]

%
% Create patterns that match the first and last characters of a string. The textBoundary function matches boundaries at the start or end of a string, while the call lettersPattern(1) matches any letter.

startPat = textBoundary + lettersPattern(1)
endPat = lettersPattern(1) + textBoundary

%
% Find the length of each string in str. To account for the first and last letters, subtract two from each length. Convert the lengths to strings.

L = strlength(str) - 2;
L = string(L)

%
% Create abbreviations for the elements of str. Replace the characters between the first and last letters with the elements of L.

newStr = replaceBetween(str,startPat,endPat,L)

%
% For a list of functions that create pattern objects, see pattern.
% Copyright 2020 The MathWorks, Inc.