title: replace user defined variable at re.sub in python
body: <pre><code>import re
  
  ip = input("Enter the value : ")
  line = "&lt;test&gt;&lt;/test&gt;"
  </code></pre>
  
  <p><strong>I tried the following scenarios</strong>     </p>
  
  <pre><code>re.sub(r'(\&lt;test\&gt;)(\&lt;\/test\&gt;)', r'\1#{ip}\2', line)
  re.sub(r'(\&lt;test\&gt;)(\&lt;\/test\&gt;)', r'\1-{ip}\2', line)
  re.sub(r'(\&lt;test\&gt;)(\&lt;\/test\&gt;)', r'\1+ip+\2', line)
  </code></pre>
  
  <p>i want to replace the line like</p>
  
  <pre><code>**&lt;test&gt;user_input&lt;/test&gt;**
  </code></pre>
  
  <p><em>how to use user defined variable in re.sub</em></p>