title: Extracting domain name from email in Python (including several special cases)
body: <p>I am trying to extract just the domain name from email string, using Python. For a basic case such as abc@xyz.com, the following works well:</p>
  
  <pre><code>string.split("@")[1].rstrip(".com")   #would give me "xyz"
  </code></pre>
  
  <p>But I was hoping to find a solution that would get the domain name for cases such as:</p>
  
  <ul>
  <li>abc@alumni.xyz.com </li>
  <li>abc@xyz.org</li>
  <li>abc@xyz.co.in</li>
  <li>abc@xyz.it</li>
  </ul>
  
  <p>One solution that comes to my mind is to use regular expression and strip off anything that follows the last dot but that still leaves special domains such as "xyz.co.sy" wherein I would expect to get just "xyz". </p>