title: Parsing a "hierarchical" URL with regexes if there are splits in parsing logic
body: <p>Is there any way to adjust the remaining regex pattern to what have been already matched? A rough sketch to illustrate the idea:</p>
  
  <pre><code>          pattern
         /     |     \
        /      |      \
  prefix1   prefix2   prefix3
     |         |         |
  postfix1  postfix2  postfix3
  </code></pre>
  
  <p>This is a rather theoretical question; the practical application below is only for illustrative purposes.</p>
  
  <p>I'm trying to find the first URLs to popular code hosting platforms, like github, gitlab etc., in a large text. The problem is, all platforms have different URL patterns:</p>
  
  <pre><code>github.com/&lt;user&gt;/&lt;repo&gt;
  gitlab.com/&lt;group1&gt;/&lt;group2&gt;/.../&lt;repo&gt;
  sourceforge.net/projects/&lt;repo&gt;
  </code></pre>
  
  <p>I can use lookbehind expressions, but then the expression gets really monstrous (Python re):</p>
  
  <pre><code>pattern = re.compile(
      r"(github\.com|bitbucket\.org|gitlab\.com|sourceforge\.net)/"
      # middle part - empty for all except sourceforge
      r"(?:(?&lt;=github\.com/)|(?&lt;=bitbucket\.org/)|(?&lt;=gitlab\.com/)|"
      r"(?&lt;=sourceforge\.net/)projects/)("
      # final part, the repository pattern
      r"(?&lt;=github\.com/)[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+|"
      r"(?&lt;=bitbucket\.org/)[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+|"
      r"(?&lt;=gitlab\.com/)[a-zA-Z0-9_.-]+(?:/[a-zA-Z0-9_.-]+)+|"
      r"(?&lt;=sourceforge\.net/projects/)[a-zA-Z0-9_.-]+"
      r")")
  </code></pre>
  
  <p>Is there a more elegant way to do something like this?</p>