title: Python regex replace and use match
body: <p>I have a text, I want to replace all the attachment:ATT000xx files to another link /dwl/attachment/ATT000xx</p>
  <pre><code>regex = &quot;attachment:ATT\d+&quot;
  txt = &quot;&lt;img src=\&quot;attachment:ATT00001\&quot;&quot;
  
  x = re.sub(&quot;attachment:ATT\d+&quot;, &quot;/dwl/attachment/&quot;, txt)
  </code></pre>
  <p>How can I find last numbers(00001/00002) and put the end of line</p>
  <p>in nodejs it will be</p>
  <pre><code>.replace(/attachment:([a-f0-9]+)\/(ATT\d+)/g, (str, mid, aid) =&gt;
  </code></pre>
  <p>aid is what I looking for for nodejs</p>