Help with Regex for domain names

Nobody nobody at nowhere.com
Thu Jul 30 14:51:23 EDT 2009


On Thu, 30 Jul 2009 10:29:09 -0700, rurpy wrote:

>> regex = re.compile(r'[\w\-\.]+\.(?:us|au|de)')
> 
> You might also want to consider that some country
> codes such as "co" for Columbia might match more than
> you want, for example:
> 
>   re.match(r'[\w\-\.]+\.(?:us|au|de|co)', 'foo.boo.com')
> 
> will match.

... so put \b at the end, i.e.:

regex = re.compile(r'[\w\-\.]+\.(?:us|au|de)\b')




More information about the Python-list mailing list