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
-
Find relatively common elements in matrix rows
2087 Solvers
-
Back to basics 25 - Valid variable names
328 Solvers
-
487 Solvers
-
Calculate the Number of Sign Changes in a Row Vector (No Element Is Zero)
765 Solvers
-
Find last zero for each column
590 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!