title: Python regex search and replace all print statement
body: <p>My sample code is written in a file containing several print statements,</p>
  
  <pre><code>def get_address(cls,latitude,longitude):
      try:
          geolocator = GoogleV3()
          location = geolocator.reverse(latitude,longitude)
          print location
          print location.address
          print "location"
          print("location")
          return (location.address)
      except Exception as e:
          print e
  </code></pre>
  
  <p>Am using regex to delete all the print statements (except print e) from this code,
  my code:</p>
  
  <pre><code>import re
  regex = r"print[/s]?[^e]?(.)+"
  try:
      print (re.sub(regex, "AA", str))
  except Exception as e:
      print e
  old_file=open("views.py")
  new_file=open("new_text.py", "w")
  for line in old_file:
      new_line = re.sub(regex, "", line)
      new_file.write(new_line)
  old_file.close()
  new_file.close()
  </code></pre>
  
  <p>my code is written in views.py, an new code in new_text.py, after running this script, <strong>print e</strong> in exception also deleted, which cause syntax error. Is there any good way to delete all print statements except <strong>print e</strong> and save code in same file.</p>