%% Search Text Using Patterns
% lettersPattern is a typical character-matching pattern that matches letter characters. Create a pattern that matches one or more letter characters.

txt = ["This" "is a" "1x6" "string" "array" "."];
pat = lettersPattern;

% Use contains to determine if characters matched by pat are present in each string. The output logical array shows that the first five of the strings in txt contain letters, but the sixth string does not.

contains(txt,pat)

% Determine if text starts with the specified pattern. The output logical array shows that four of the strings in txt start with letters, but two strings do not.

startsWith(txt,pat)

% Determine if the string fully matches the specified pattern. The output logical array shows which of the strings in txt contain nothing but letters.

matches(txt,pat)

% Count the number of times a pattern matched. The output numerical array shows how many times lettersPattern matched in each element of txt. Note that lettersPattern matches one or more letters so a group of concurrent letters is a single match.

count(txt,pat)

% Copyright 2020 The MathWorks, Inc.