title: RegExp to match depending on previous match
body: <p>I have a huge (~1000 lines) .htaccess file that I need to clean up from redundant 301 redirects.</p>
  
  <p>I was thinking of using RegExp to help but I reached my limit in this.</p>
  
  <p>All the redirects that I need to remove are on the same pattern </p>
  
  <p><code>Redirect 301 /visite/ /fr/visite/</code></p>
  
  <p>In that case, I want to match that what follows the "Redirect 301" is the same as what follows with the addition of /LANG (I have /fr /en and /de) and remove the line completely.</p>
  
  <p>Basically, anything that matches the following needs to be removed </p>
  
  <p><code>Redirect 301 /some_URL/ /LANG/some_URL/</code></p>
  
  <p>However, some redirects need to remain active, such as below.</p>
  
  <p><code>Redirect 301 /lavaux-vineyard /en/explore/unesco-listed-lavaux-vineyard-terraces/</code></p>
  
  <p>Here is a link to the complete file in question: <a href="https://gofile.io/d/l3xC0k" rel="nofollow noreferrer">https://gofile.io/d/l3xC0k</a></p>
  
  <p>Thank you very much in advance for your help.</p>