Man I'm surprised how difficult of a time I had learning this module. I got into it because I bought the udemy "Automate the boring stuff with python" course. Although having the physical book probably would've been much better, I must say regardless other tutorials on youtube were much easier to follow. But anyway I digress. I just tried making my own challenges and god it took me a while to get it right. But now that I did get it to work, I would like to see if there is a more efficient way to do it or just different way. I'm very sure there are several. Please let me know what you think.
Furthermore it would be nice if I could see a version where numbers are grouped by names "area code", "prefix", and "line". And then substitute the last two digits with "XX"
Python:
import re
# find and extract all area codes that are reasonably cipherable as an area code
message = "801-111-1111,802-222-2222, (803)-333-3333,(804) 444-4444, -805-555-5555, 806 666-6666"
pattern_object = r'\(\d\d\d\)|\d\d\d(?=-\d\d\d-)|\d\d\d(?= \d\d\d-)'
checked = re.compile(pattern_object)
area_codes = checked.findall(message)
# found_obj = checked.search(message)
# print(area_codes)
for area_code in area_codes:
print(area_code)
Furthermore it would be nice if I could see a version where numbers are grouped by names "area code", "prefix", and "line". And then substitute the last two digits with "XX"
Last edited: