title: How to change original match in re.sub
body: <p>I want to split text in my <code>html</code> using <code>&lt;br&gt;</code> tags. If the text is longer than 50 characters, I want to replace last space before 10 characters by <code>&lt;br&gt;</code>.</p>
  
  <p>The text is in <code>&lt;span class="value"&gt;TEXT&lt;/span&gt;</code></p>
  
  <p>For example <code>&lt;span class="value"&gt;cccc cc cccccc cccc cc c&lt;/span&gt;</code></p>
  
  <p>Will became: <code>&lt;span class="value"&gt;cccc cc&lt;br&gt;cccccc&lt;br&gt;cccc cc c&lt;/span&gt;</code> so every line can have at most 10 characters.</p>
  
  <p>I've created a regex for this which can probably find such tags but can't figure out how to extract text from matched group and then replace it.</p>
  
  <pre><code>snippet = re.sub(r'&lt;span class="value"&gt;(.*)&lt;\/span&gt;', 
                   r'&lt;span class="value"&gt;\1&lt;\/span&gt;'.(divide text using &lt;br&gt; tags) 
  </code></pre>
  
  <p>Do you know how to do that?</p>