Problem 91. Get the area codes from a list of phone numbers
Given a string of text with phone numbers in it, return a unique'd cell array of strings that are the area codes.
s = '508-647-7000, (508) 647-7001, 617-555-1212';
then
a = {'508','617'}
Note: This problem refers to American-style phone numbers. You can assume the first three digits of a ten-digit number will always be the area code.
Solution Stats
Problem Comments
-
6 Comments
Show
3 older comments
Rafael S.T. Vieira
on 12 Jun 2020
The problem fails to mention that the area codes should be sorted, and that phone numbers may have country codes.
Rik
on 15 Jan 2021
This isn't about American-style phone numbers, but US-style. Otherwise it would be nice to include other test cases so people would be required to actually parse the country code away. Now it is just a matter of removing a leading 1.
Tran Tran
on 31 Jul 2022
Madness of cellfun regexp
Solution Comments
Show commentsProblem Recent Solvers1062
Suggested Problems
-
1965 Solvers
-
276 Solvers
-
465 Solvers
-
625 Solvers
-
Count consecutive 0's in between values of 1
453 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!