'''
Created on Nov 4, 2013

@author: rcd
'''
import re

f = open('phone_numbers.txt')
numbers = f.read()
f.close()

PHONE_PATTERN = r'\(?(\d{3})\)?\s*[\.-]?\s*(\d{3})\s*[\.-]?\s*(\d{4})'
PHONE_PATTERN_COMMENTED = re.compile(r"""
 \(?               # might start with a (, not necessary but symmetric
 (\d{3})           # the area code (remember it)
 \)?               # might have one closing )
 \s*[\.-]?\s*      # separators between the numbers
 (\d{3})           # the root of the number (remember it)
 \s*[\.-]?\s*      # separators between the numbers
 (\d{4})           # the number's extension (remember it)
""", re.VERBOSE)

print(re.findall(PHONE_PATTERN, numbers))
print(PHONE_PATTERN_COMMENTED.findall(numbers))
