Python equivalent of Perl e flag with regular expression

Friedman, Jason jfriedman at
Thu Oct 2 19:06:40 CEST 2008

I have lines that look like this:
select column1, 'select' as type
from table
where column2 = 'foo'

I want to return:
SELECT column1, 'select' AS type
FROM table
WHERE column2 = 'foo'

This is SQL with the keywords converted to uppercase.  Note that the
second "select" string is not a keyword and thus I do not want to
convert it to uppercase.  Thus, I don't think the string.replace()
method will work for me.

With Perl I might do something like this:
$line =~ s/(select)/uc($1)/e;
More generally:
for $keyword in (@keyword) {
  $line =~ s/($keyword)/uc($1)/e;

How would I do this with Python?

This e-mail transmission may contain information that is proprietary, privileged and/or confidential and is intended exclusively for the person(s) to whom it is addressed. Any use, copying, retention or disclosure by any person other than the intended recipient or the intended recipient's designees is strictly prohibited. If you are not the intended recipient or their designee, please notify the sender immediately by return e-mail and delete all copies. OppenheimerFunds may, at its sole discretion, monitor, review, retain and/or disclose the content of all email communications. 

More information about the Python-list mailing list