[Tutor] regex question

Peter Otten __peter__ at web.de
Fri Apr 6 08:57:24 CEST 2012


Khalid Al-Ghamdi wrote:

> I'm trying to extract the domain in the following string. Why doesn't my
> pattern (patt) work:
> 
>>>> redata
> 'Tue Jan 14 00:43:21 2020::eaximi at gstwyysnbd.gov::1578951801-6-10 Sat Jul
> 31 15:17:39 1993::rzppg at wgxvhx.com::744121059-5-6 Mon Sep 21 20:22:37
> 1987::ttwqrf at rpybrct.edu::559243357-6-7 Fri Aug  2 07:15:23
> 1991::tjyp at mgfyitsks.net::681106523-4-9 Mon Mar 18 19:59:47
> 2024::dgzxmb at fhyykji.org::1710781187-6-7 '
>>>> patt=r'\w+\.\w{3}(?<=@)'
>>>> re.findall(patt,redata)
> []
> 
> This pattern works but the first should, too. shouldn't it?

No. I think you want r'(?<=@)\w+\.\w{3}'.

How do you handle a domain like web.de, by the way?




More information about the Tutor mailing list