| Labeling Your Output Named tokens can also be useful in labeling the output from the MATLAB regular expression functions. This is especially true when you are processing numerous strings. This example parses different pieces ofstreet addresses from several strings. A short name is assigned to each token in the expression string: str1 = '134 Main Street, Boulder, CO, 14923'; str2 = '26 Walnut Road, Topeka, KA, 25384'; str3 = '847 Industrial Drive, Elizabeth, NJ, 73548'; p1 = '(?<adrs>\d+\s\S+\s(Road|Street|Avenue|Drive))'; p2 = '(?<city>[A-Z][a-z]+)'; p3 = '(?<state>[A-Z]{2})'; p4 = '(?<zip>\d{5})'; expr = [p1 ', ' p2 ', ' p3 ', ' p4]; As the following results demonstrate, you can make your output easier to work with by using named tokens: loc1 = regexp(str1, expr, 'names') loc1 = adrs: '134 Main Street' city: 'Boulder' state: 'CO' zip: '14923' loc2 = regexp(str2, expr, 'names') loc2 = adrs: '26 Walnut Road' city: 'Topeka' state: 'KA' zip: '25384' loc3 = regexp(str3, expr, 'names') loc3 = adrs: '847 Industrial Drive' city: 'Elizabeth' |