title: How to replace text in repeated fragments inside parent text using re module?
body: <p>I have html file, that contains repeated <strong><code>code</code></strong> tags:</p>
  <pre class="lang-html prettyprint-override"><code>
  &lt;h3&gt;Post header content&lt;/h3&gt;
  
  &lt;p&gt;
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum, delectus.
  &lt;/p&gt;
  
  &lt;p&gt;
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam culpa illo necessitatibus 
      officia sed totam. Aspernatur cupiditate debitis eos obcaecati! Dolores eveniet excepturi hic optio.
  &lt;/p&gt;
  
  &lt;code class=&quot;code&quot;&gt;
  $ pip install --no-cache-dir -r requirements.txt
  
  &lt;/code&gt;
  
  
  &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit. 
      Accusamus et hic neque, suscipit totam ullam.&lt;/p&gt;
  
  
  &lt;code class=&quot;code&quot;&gt;
  
  // Linux
  export FLASK_APP=app.py
  export FLASK_ENV=development
  
  // Windows
  set FLASK_APP=app.py
  set FLASK_ENV=development
  
  &lt;/code&gt;
  
  &lt;p&gt;More text...&lt;/p&gt;
  
  
  </code></pre>
  <p>I want to find all <strong><code>code</code></strong> tags, make with them some sting operations and return to source string.
  This is a fragment of my code:</p>
  <pre class="lang-py prettyprint-override"><code>import re
  
  def code2replace(code):
      # find all code fragments
      RE_CODE = r'&lt;code[^&gt;]+&gt;(.*?)&lt;\/code&gt;'
      matches = re.finditer(RE_CODE, code, re.S)
      
  
      rs_text = ''
      code_text = ''
      pos_start = 0
  
      for match in matches:
          # print(f'Start: {match.start()}, End: {match.end()}, Content: {match.group(1)}')
          code_text = match.group(1).replace('\n', '\n&lt;br/&gt;')
  
          rs_text += code[pos_start: match.start()] + f'&lt;code class=&quot;code&quot;&gt;{code_text}&lt;/code&gt;'
          pos_start = match.end()
  
      return rs_text
  
  
  </code></pre>
  <p>But unfortunately this is not work correctly.</p>
  <p>So, how to change content of <strong><code>code</code></strong> tags inside this html and return changed result?</p>