Question: Suppose I got these urls.

```
http://abdd.eesfea.domainname.com/b/33tA$/0021/file
http://mail.domainname.org/abc/abc/aaa
http://domainname.edu 

```

I just want to extract "domainame.com" or "domainname.org" or "domainname.edu" out.
How can I do this?

I think, I need to find the last "dot" just before "com|org|edu..." and print out content from this "dot"'s previous dot to this dot's next dot(if it has).

Need help about the regular-expres.
Thanks a lot!!!
I am using Python.

Answer: 
why use regex?

<http://docs.python.org/library/urlparse.html>
Should you need more flexibility than `urlparse` provides, here's an example to get you started:

```
import re
def getDomain(url):
    #requires 'http://' or 'https://'
    #pat = r'(https?):\/\/(\w+\.)*(?P<domain>\w+)\.(\w+)(\/.*)?'
    #'http://' or 'https://' is optional
    pat = r'((https?):\/\/)?(\w+\.)*(?P<domain>\w+)\.(\w+)(\/.*)?'
    m = re.match(pat, url)
    if m:
        domain = m.group('domain')
        return domain
    else:
        return False

```

I used the named group `(?P<domain>\w+)` to grab the match, which is then indexed by its name, `m.group('domain')`.
The great thing about learning regular expressions is that once you are comfortable with them, solving even the most complicated parsing problems is relatively simple. This pattern could be improved to be more or less forgiving if necessary -- this one for example will return '678' if you pass it 'http://123.45.678.90', but should work great on just about any other URL you can come up with. [Regexr](http://gskinner.com/RegExr/) is a great resource for learning and testing regexes.