title: Python - Regex - IP - no result
body: <p>I wrote some code to extract email and IP addresses from bulk text. However, the code extracts only the email addresses. <em>(The original text, which I would like to make understandable, is a typical log file)</em>. I don't know why the generated file does not give me back the IP addresses.</p>
  
  <pre><code>import os
  import re
  
  # 1
  filename = 'errors.txt'
  newfilename = 'emaillist-rev.txt'
  
  # 2
  if os.path.exists(filename):
      data = open(filename,'r')
      bulkemails = data.read()
  
  
  else:
      print "File not found."
      raise SystemExit
  
  # 3
  r = re.compile(r'[\w\.-]+@[\w\.-]+')
  results = r.findall(bulkemails)    
  
  emails = ""   
  for x in results:
      emails += str(x)+"\n"   
  
  
  # 4
  ip = re.compile('^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$')
  result = ip.findall(bulkemails)
  
  ip =""
  for y in result:
      ip += str(y)+"\n"
  
  # 5
  def writefile():
      f = open(newfilename, 'w')
      f.write(emails + ip)
      f.close()
      print "File written."
  
  # 6
  def overwrite_ok():
      response = raw_input("Are you sure you want to overwrite "+str(newfilename)+"? Yes or No\n")
      if response == "Yes":
          writefile()
      elif response == "No":
          print "Aborted."
      else:
          print "Please enter Yes or No."
          overwrite_ok()
  
  # 7
  if os.path.exists(newfilename):
      overwrite_ok()      
  else: 
      writefile()
  </code></pre>