title: Replace all matches using re.findall()
body: <p>Using <code>re.findall()</code> I've managed to get return multiple matches of a regex in a string. However my object returned is a list of matches within the string. This is not what I want.</p>
  
  <p>What I want is to replace all matches with something else. I've tried to use similar syntax as you would use in re.sub to do this as so:</p>
  
  <pre><code>import json
  import re
  
  regex = re.compile('([a-zA-Z]\"[a-zA-Z])', re.S)
  
  filepath = "C:\\Python27\\Customer Stuff\\Austin Tweets.txt"
  
  f = open(filepath, 'r')
  myfile = re.findall(regex, '([a-zA-Z]\%[a-zA-Z])', f.read())
  print myfile
  </code></pre>
  
  <p>However, this creates the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/Python27/Customer Stuff/Austin's Script.py", line 9, in &lt;module&gt;
      myfile = re.findall(regex, '([a-zA-Z]\%[a-zA-Z])', f.read())
    File "C:\Python27\lib\re.py", line 177, in findall
      return _compile(pattern, flags).findall(string)
    File "C:\Python27\lib\re.py", line 229, in _compile
      bypass_cache = flags &amp; DEBUG
  TypeError: unsupported operand type(s) for &amp;: 'str' and 'int'
  </code></pre>
  
  <p>Can anyone assist me within the last bit of syntax I need to replace all matches with something else within the original Python object?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>In line with comments and answers received, here is me trying to sub one regex with another:</p>
  
  <pre><code>import json
  import re
  
  regex = re.compile('([a-zA-Z]\"[a-zA-Z])', re.S)
  regex2 = re.compile('([a-zA-Z]%[a-zA-Z])', re.S)
  
  filepath = "C:\\Python27\\Customer Stuff\\Austin Tweets.txt"
  
  f = open(filepath, 'r')
  myfile = f.read()
  myfile2 = re.sub(regex, regex2, myfile)
  print myfile
  </code></pre>
  
  <p>This now produces the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/Python27/Customer Stuff/Austin's Script.py", line 11, in &lt;module&gt;
      myfile2 = re.sub(regex, regex2, myfile)
    File "C:\Python27\lib\re.py", line 151, in sub
      return _compile(pattern, flags).sub(repl, string, count)
    File "C:\Python27\lib\re.py", line 273, in _subx
      template = _compile_repl(template, pattern)
    File "C:\Python27\lib\re.py", line 258, in _compile_repl
      p = sre_parse.parse_template(repl, pattern)
    File "C:\Python27\lib\sre_parse.py", line 706, in parse_template
      s = Tokenizer(source)
    File "C:\Python27\lib\sre_parse.py", line 181, in __init__
      self.__next()
    File "C:\Python27\lib\sre_parse.py", line 183, in __next
      if self.index &gt;= len(self.string):
  TypeError: object of type '_sre.SRE_Pattern' has no len()
  </code></pre>