%% Match Domain and Subdomains of Email Addresses
% Build a pattern that matches combinations of letters and periods after an "@". Use optionPattern to match subdomains if present. If a subdomain is not present, optionalPattern does not prevent a match if other conditions of pat are met. Extract the pattern.

emails = ["Sue_B@nonprofit.org"
          "JohnDRoc12@business.com"
          "R.Franklin@biology.university.org"];
pat = lookBehindBoundary("@") + optionalPattern(lettersPattern + ".") + lettersPattern + "." + lettersPattern;
domains = extract(emails,pat)

% Copyright 2020 The MathWorks, Inc.