Perl s/ To Python?

J

John Abel

Does anyone know of a quick way of performing this:

$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.

J
 
J

JZ

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)
 
J

John Abel

JZ said:
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)
That's brill. Never even thought if using re. Thank you!

J
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top