%% Count Digits and Letters Using Patterns
% Since R2020b
% Create a string array that contains addresses.

str = ["221B Baker St.","Tour Eiffel Champ de Mars","4059 Mt Lee Dr."]

%
% To count the digits in each address, first create a pattern that matches a single digit. The number of times this pattern occurs in a string equals the number of digits in the string.
% Create the pattern by calling the digitsPattern function with 1 as the input argument. When you do this, it matches a single digit (such as 2) instead of an arbitrary sequence of digits (such as 221 or 4059).

pat = digitsPattern(1)

%
% Then call the count function with str and pat as inputs.

A = count(str,pat)

%
% Similarly, you can count the number of letters (not including digits, spaces, or punctuations marks) by using the pattern created by lettersPattern(1).

A = count(str,lettersPattern(1))

%
% Count sequences consisting of one or more digits and then one letter. You can build more complex patterns by combining simple patterns. In this case, digitsPattern + lettersPattern(1) matches 221B.

pat = digitsPattern + lettersPattern(1);
A = count(str,pat)

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