title: How to replace all occurrences of a match pattern in a line?
body: <p>Suppose I have a line like:</p>
  
  <pre><code>"[foo] and (foo) along with foofrancis.foo = foo"
  </code></pre>
  
  <p>Where the match pattern <code>"foo"</code> is always contiguous to non <code>a-zA-Z</code> characters but may occur any number of times in a line. </p>
  
  <p>I want to replace all occurrences of <code>"foo"</code> with <code>"bar"</code> when foo is not contiguous to an a-z or A-Z character and output a newline.</p>
  
  <p>Where <code>foo</code> and <code>bar</code> are both variables I am passing in. Sort of like:</p>
  
  <pre><code> foo = "Hello"
   bar = "Goodbye"
   line = "[Hello] and (Hello) along with Hellofrancis.Hello = Hello"
   newline = re.sub(&lt;Unsure what goes here&gt;,line)
   print newline
  </code></pre>
  
  <p>Output:</p>
  
  <pre class="lang-none prettyprint-override"><code>[Goodbye] and (Goodbye) along with Hellofrancis.Goodbye = Goodbye
  </code></pre>
  
  <p>I'm not sure how I configure my <code>re.sub</code></p>