Perl s/ To Python?

Discussion in 'Python' started by John Abel, Jun 10, 2005.

  1. John Abel

    John Abel Guest

    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
    John Abel, Jun 10, 2005
    #1
    1. Advertising

  2. John Abel

    JZ Guest

    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
    JZ, Jun 10, 2005
    #2
    1. Advertising

  3. John Abel

    John Abel Guest

    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
    John Abel, Jun 10, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    1,791
  2. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Jan 23, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    297
    PerlFAQ Server
    Jan 23, 2011
  3. PerlFAQ Server
    Replies:
    0
    Views:
    677
    PerlFAQ Server
    Feb 3, 2011
  4. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Feb 27, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    291
    PerlFAQ Server
    Feb 27, 2011
  5. PerlFAQ Server
    Replies:
    0
    Views:
    679
    PerlFAQ Server
    Apr 4, 2011
Loading...

Share This Page