title: Find USA phone numbers in python script
body: <p>the following python script allows me to scrape email addresses from a given file using regular expressions. </p>
  
  <p>How could I add to this so that I can also get phone numbers? Say, if it was either the 7 digit or 10 digit (with area code), and also account for parenthesis? </p>
  
  <p><strong>My current script can be found below:</strong></p>
  
  <pre><code># filename variables
  filename = 'file.txt'
  newfilename = 'result.txt'
  
  # read the file
  if os.path.exists(filename):
          data = open(filename,'r')
          bulkemails = data.read()
  else:
          print "File not found."
          raise SystemExit
  
  # regex = something@whatever.xxx
  r = re.compile(r'(\b[\w.]+@+[\w.]+.+[\w.]\b)')
  results = r.findall(bulkemails)
  emails = ""
  for x in results:
          emails += str(x)+"\n"
  
  # function to write file
  def writefile():
          f = open(newfilename, 'w')
          f.write(emails)
          f.close()
          print "File written."
  </code></pre>
  
  <p>Regex for phone numbers:</p>
  
  <pre><code>(\d{3}[-\.\s]\d{3}[-\.\s]\d{4}|\(\d{3}\)\s*\d{3}[-\.\s]\d{4}|\d{3}[-\.\s]\d{4})
  </code></pre>
  
  <p>Another regex for phone numbers:</p>
  
  <pre><code>(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?
  </code></pre>