Re: Python equivalent of Perl e flag with regular expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • skip@pobox.com

    Re: Python equivalent of Perl e flag with regular expression


    JasonWith Perl I might do something like this:
    Jason$line =~ s/(select)/uc($1)/e;
    ...
    JasonHow would I do this with Python?

    I'm sure there are plenty of ways to skin this particular cat, but how is
    's/.../.../e' different from 's/.../.../'? (For those of us who are not
    Perl mongers.)

    Skip
  • Mark Thomas

    #2
    Re: Python equivalent of Perl e flag with regular expression

    On Oct 2, 4:03 pm, s...@pobox.com wrote:
        JasonWith Perl I might do something like this:
        Jason$line =~ s/(select)/uc($1)/e;
        ...
        JasonHow would I do this with Python?
    >
    I'm sure there are plenty of ways to skin this particular cat, but how is
    's/.../.../e' different from 's/.../.../'?  (For those of us who are not
    Perl mongers.)
    >
    Skip
    The '/e' means that the replacement string is actually code to be
    executed, the output of which becomes the replacement string.

    Perl even allows '/ee' which executes the code, then takes the output
    of that and executes it again. In fact, you can have an arbitrary
    number of e's, which is very handy for crazy people.

    -- Mark.

    Comment

    Working...