By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,222 Members | 2,374 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,222 IT Pros & Developers. It's quick & easy.

Perl s/ To Python?

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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)

--
JZ
Jul 19 '05 #2

P: n/a
JZ wrote:
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

That's brill. Never even thought if using re. Thank you!

J
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.