Perl s/ To Python?

JZ usenet at zabiello.com
Fri Jun 10 10:10:18 EDT 2005


Dnia Fri, 10 Jun 2005 14:57:21 +0100, John Abel napisał(a):

> $testVar =~ s#/mail/.*$##g
> 
> The only way I can think of doing it, is:
> 
> mailPos = testVar.find( "mail" )
> remainder =  testVar[ :mailPos ]
> 
> Any ideas would be appreciated.  I'm iterating over a lot of entries, 
> and running these lines for each entry.

import re
testVar = re.compile(r'/mail/.*$').sub('', testVar) 

--
JZ



More information about the Python-list mailing list