%% Edit Text Using Patterns
% digitsPattern is a typical character-matching pattern that matches digit characters. Create a pattern that matches digit characters.

txt = ["1 fish" "2 fish" "[1,0,0] fish" "[0,0,1] fish"];
pat = digitsPattern;

% Use replace to edit pieces of text that match the pattern.

replace(txt,pat,"#")

% Create a new piece of text by inserting an "!" character after matched letters.

insertAfter(txt,pat,"!")

% Patterns can be created using the OR operator, |, with text.  Erase text matched by the specified pattern.

txt = erase(txt,"," | "]" | "[")

% Extract pat from the new text.

extract(txt,pat)

% Copyright 2020 The MathWorks, Inc.