Cannot formulate regex

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Sun Sep 16 11:46:09 EDT 2007


Dotan Cohen schreef:
> I'd like to filter spam from a certain company. Here are examples of
> strings found in their spam:
> Mega Dik
> Mega D1k
> MegaDik
> Mega. Dik
> M eg ad ik
> M E _G_A_D_ IK
> M_E_G. ADI. K
> 
> I figured that this regex would match all but the second example, yet
> it matches none:
> |[^a-z]m[^a-z]e[^a-z]g[^a-z]a[^a-z]d[^a-z]i[^a-z]k[^a-z]|i
> 
> What would be the regex that matches "megadik" regardless of whatever
> characters are sprinkled throughout?

m[^a-z]*e[^a-z]*g[^a-z]*a[^a-z]*d[^a-z]*i[^a-z]*k

FYI Kodos (http://kodos.sourceforge.net/) can be very useful for 
developing, testing and debugging such regexes.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven



More information about the Python-list mailing list